|
|
@ -752,10 +752,12 @@ void ThreadSocketHandler2(void* parg) |
|
|
|
FD_ZERO(&fdsetSend); |
|
|
|
FD_ZERO(&fdsetSend); |
|
|
|
FD_ZERO(&fdsetError); |
|
|
|
FD_ZERO(&fdsetError); |
|
|
|
SOCKET hSocketMax = 0; |
|
|
|
SOCKET hSocketMax = 0; |
|
|
|
|
|
|
|
bool have_fds = false; |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) { |
|
|
|
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) { |
|
|
|
FD_SET(hListenSocket, &fdsetRecv); |
|
|
|
FD_SET(hListenSocket, &fdsetRecv); |
|
|
|
hSocketMax = max(hSocketMax, hListenSocket); |
|
|
|
hSocketMax = max(hSocketMax, hListenSocket); |
|
|
|
|
|
|
|
have_fds = true; |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
@ -766,6 +768,7 @@ void ThreadSocketHandler2(void* parg) |
|
|
|
FD_SET(pnode->hSocket, &fdsetRecv); |
|
|
|
FD_SET(pnode->hSocket, &fdsetRecv); |
|
|
|
FD_SET(pnode->hSocket, &fdsetError); |
|
|
|
FD_SET(pnode->hSocket, &fdsetError); |
|
|
|
hSocketMax = max(hSocketMax, pnode->hSocket); |
|
|
|
hSocketMax = max(hSocketMax, pnode->hSocket); |
|
|
|
|
|
|
|
have_fds = true; |
|
|
|
{ |
|
|
|
{ |
|
|
|
TRY_LOCK(pnode->cs_vSend, lockSend); |
|
|
|
TRY_LOCK(pnode->cs_vSend, lockSend); |
|
|
|
if (lockSend && !pnode->vSend.empty()) |
|
|
|
if (lockSend && !pnode->vSend.empty()) |
|
|
@ -775,15 +778,16 @@ void ThreadSocketHandler2(void* parg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vnThreadsRunning[THREAD_SOCKETHANDLER]--; |
|
|
|
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]++; |
|
|
|
vnThreadsRunning[THREAD_SOCKETHANDLER]++; |
|
|
|
if (fShutdown) |
|
|
|
if (fShutdown) |
|
|
|
return; |
|
|
|
return; |
|
|
|
if (nSelect == SOCKET_ERROR) |
|
|
|
if (nSelect == SOCKET_ERROR) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int nErr = WSAGetLastError(); |
|
|
|
if (have_fds) |
|
|
|
if (hSocketMax != INVALID_SOCKET) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int nErr = WSAGetLastError(); |
|
|
|
printf("socket select error %d\n", nErr); |
|
|
|
printf("socket select error %d\n", nErr); |
|
|
|
for (unsigned int i = 0; i <= hSocketMax; i++) |
|
|
|
for (unsigned int i = 0; i <= hSocketMax; i++) |
|
|
|
FD_SET(i, &fdsetRecv); |
|
|
|
FD_SET(i, &fdsetRecv); |
|
|
|