diff options
| author | Wladimir J. van der Laan <[email protected]> | 2012-09-06 23:30:22 -0700 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2012-09-06 23:30:22 -0700 |
| commit | f106491fa2ef8fa78fa6e9ad9a343935bd0fc5f1 (patch) | |
| tree | 40158db09ea8868b35e3a24a89a5496a56670663 /src/net.cpp | |
| parent | Fix double-paren typo (diff) | |
| parent | select(): Use precise fd presence check, rather than imprecise hSocketMax test (diff) | |
| download | discoin-f106491fa2ef8fa78fa6e9ad9a343935bd0fc5f1.tar.xz discoin-f106491fa2ef8fa78fa6e9ad9a343935bd0fc5f1.zip | |
Merge pull request #1786 from jgarzik/select-fix
select()'s first argument should be zero, if no file descriptors are selected
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 11bade6bb..c0693306a 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); |