From 3c43517e44c85c4a09f154900ee33d55f605ef1b Mon Sep 17 00:00:00 2001 From: Chris Teubert Date: Sun, 26 Apr 2015 13:48:06 -0700 Subject: [PATCH] Fix Bug in getDREF Response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix Bug- readUDP loop in getDREF Response only ran once no matter what. This wasn’t enough time for the plugin to send a response. Note: You can try increasing the timeout, but the plugin has to have a socket with a timeout of 1ms or less. If the timeout is higher than that a lag is introduced. --- C/src/xplaneConnect.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 9e7ba5b..b065bd0 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -432,23 +432,24 @@ int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int si // Read data. Try 40 times to read, then give up. // TODO: Why not just set the timeout to 40ms? int result; - for (int i = 0; i < 512; ++i) + for (int i = 0; i < 40; ++i) { result = readUDP(sock, buffer, 65536); if (result > 0) { break; } - if (result < 0) - { -#ifdef _WIN32 - printError("getDREFs", "Read operation failed. (%d)", WSAGetLastError()); -#else - printError("getDREFs", "Read operation failed."); -#endif - return -1; - } } + + if (result < 0) + { +#ifdef _WIN32 + printError("getDREFs", "Read operation failed. (%d)", WSAGetLastError()); +#else + printError("getDREFs", "Read operation failed."); +#endif + return -1; + } if (result < 6) {