Fix select() calls - nfds must be the highest fd value plus 1

* This was copy-pasted from windows where unfortunately the nfds
  argument is ignored and we could get away with just passing 0 (which
  I suspect is where the broken code came from originally - a windows
  example code that passed 0)
This commit is contained in:
baldurk
2016-08-24 12:12:50 +02:00
parent 3e5d55d1d6
commit a1d0b72e79
2 changed files with 2 additions and 20 deletions
+1 -10
View File
@@ -311,7 +311,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS)
timeval timeout;
timeout.tv_sec = (timeoutMS / 1000);
timeout.tv_usec = (timeoutMS % 1000) * 1000;
result = select(0, NULL, &set, NULL, &timeout);
result = select(s + 1, NULL, &set, NULL, &timeout);
if(result <= 0)
{
@@ -319,22 +319,13 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS)
close(s);
continue;
}
else
{
RDCDEBUG("connect before timeout");
}
}
else
{
RDCDEBUG("problem other than blocking");
close(s);
continue;
}
}
else
{
RDCDEBUG("connected immediately");
}
int nodelay = 1;
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay));
+1 -10
View File
@@ -326,7 +326,7 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS)
timeval timeout;
timeout.tv_sec = (timeoutMS / 1000);
timeout.tv_usec = (timeoutMS % 1000) * 1000;
result = select(0, NULL, &set, NULL, &timeout);
result = select((int)s + 1, NULL, &set, NULL, &timeout);
if(result <= 0)
{
@@ -334,22 +334,13 @@ Socket *CreateClientSocket(const char *host, uint16_t port, int timeoutMS)
closesocket(s);
continue;
}
else
{
RDCDEBUG("connect before timeout");
}
}
else
{
RDCDEBUG("problem other than blocking");
closesocket(s);
continue;
}
}
else
{
RDCDEBUG("connected immediately");
}
BOOL nodelay = TRUE;
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char *)&nodelay, sizeof(nodelay));