aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-09-05 16:01:28 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-09-05 16:01:28 -0400
commit2387944782fa61a3137afda91e9e8105d8cc5ddf (patch)
tree9d3df5c8332b935dcb4f3c8866a1b46580aea1a1 /src
parent42613c97d5dd8581d8dfd2cbe443736f8c539973 (diff)
select(): Use precise fd presence check, rather than imprecise hSocketMax test
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 76e44a6cf8..2c6efff63c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -752,10 +752,12 @@ void ThreadSocketHandler2(void* parg)
FD_ZERO(&fdsetSend);
FD_ZERO(&fdsetError);
SOCKET hSocketMax = 0;
+ bool have_fds = false;
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) {
FD_SET(hListenSocket, &fdsetRecv);
hSocketMax = max(hSocketMax, hListenSocket);
+ have_fds = true;
}
{
LOCK(cs_vNodes);
@@ -766,6 +768,7 @@ void ThreadSocketHandler2(void* parg)
FD_SET(pnode->hSocket, &fdsetRecv);
FD_SET(pnode->hSocket, &fdsetError);
hSocketMax = max(hSocketMax, pnode->hSocket);
+ have_fds = true;
{
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend && !pnode->vSend.empty())
@@ -775,15 +778,16 @@ void ThreadSocketHandler2(void* parg)
}
vnThreadsRunning[THREAD_SOCKETHANDLER]--;
- int nSelect = select(hSocketMax + 1, &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
+ int nSelect = select(have_fds ? hSocketMax + 1 : 0,
+ &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
vnThreadsRunning[THREAD_SOCKETHANDLER]++;
if (fShutdown)
return;
if (nSelect == SOCKET_ERROR)
{
- int nErr = WSAGetLastError();
- if (hSocketMax != INVALID_SOCKET)
+ if (have_fds)
{
+ int nErr = WSAGetLastError();
printf("socket select error %d\n", nErr);
for (unsigned int i = 0; i <= hSocketMax; i++)
FD_SET(i, &fdsetRecv);