Updated C client socket timeout.

The C client previously set a very short read timeout because it was required
 by the plugin. To compensate for this on the client side, we would try to
read several times in a loop. Since the plugin no longer uses the C client for
networking, we can do away with the loops and set a proper timeout.
This commit is contained in:
Jason Watkins
2015-04-30 09:01:09 -07:00
parent 39c2f58a54
commit 902aa006e8

View File

@@ -109,12 +109,13 @@ XPCSocket aopenUDP(const char *xpIP, unsigned short xpPort, unsigned short port)
exit(EXIT_FAILURE);
}
// Set timeout to 100ms
#ifdef _WIN32
DWORD timeout = 1; // Minimum socket timeout in Windows is 1ms
DWORD timeout = 100;
#else
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 500;
timeout.tv_usec = 1000;
#endif
if (setsockopt(sock.sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0)
{
@@ -245,15 +246,8 @@ int setCONN(XPCSocket* sock, unsigned short port)
*sock = aopenUDP(sock->xpIP, sock->xpPort, port);
// Read response
int result;
for (int i = 0; i < 64; ++i)
{
result = readUDP(*sock, buffer, 32);
if (result != 0)
{
break;
}
}
int result = readUDP(*sock, buffer, 32);
if (result <= 0)
{
printError("setCONN", "Failed to read response");
@@ -429,17 +423,7 @@ int sendDREFRequest(XPCSocket sock, const char* drefs[], unsigned char count)
int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int sizes[])
{
unsigned char buffer[65536];
// 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)
{
result = readUDP(sock, buffer, 65536);
if (result > 0)
{
break;
}
}
int result = readUDP(sock, buffer, 65536);
if (result < 0)
{