The most portable invocation for the zero-fds case, a widely used portable hack for sleeping, generally involves passing NULL arguments when the fd sets are unused. This form is used here.
Intended to supercede #1772.
Yes, adding an extra flag should solve the problem too. ACK
781 | + 782 | vnThreadsRunning[THREAD_SOCKETHANDLER]--; 783 | - int nSelect = select(hSocketMax + 1, &fdsetRecv, &fdsetSend, &fdsetError, &timeout); 784 | + if (have_fds) 785 | + nSelect = select(hSocketMax + 1, 786 | + &fdsetRecv, &fdsetSend, &fdsetError, &timeout);
What adds such a line-break to readability?
Indeed, that WSAEINVAL: the time-out value is not valid, or all three descriptor parameters were null comes from the MS documentation http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx
So yes on Windows you still need the check to prevent error spam. It appears that windows does not allow for using select as simply a timeout. However, now you can check for have_fds instead of hSocketMax!=0, which is at least correct.
Yes, I understand it comes from the documentation, but is it actually seen after applying this patch?
It makes sense that it still occurs because windows ignores the nfds argument. So this change is a no-op from the viewpoint of winsock.
We could spare ourselves worrying about all these kinds of low-level OS details if we used an abstraction such as boost::asio (which will also use more efficient mechanisms such as epoll on platforms that support them).
That is what I tried to say @jgarzik, his patch does not prevent the 10022 spam, I read the select() documentation on MSDN more than once to understand what is happening ^^.
I rather sure most part of that network code are still from Satoshi (at least he was the one who merged them to Github at first).
788 | {
789 | - int nErr = WSAGetLastError();
790 | - if (hSocketMax != INVALID_SOCKET)
791 | + if (have_fds)
792 | {
793 | + int nErr = WSAGetLastError();
When making my pulls obsolete, which makes sense here to have 1 instead of 2 to fix this, could you please merge the WSAGetLastError() into the printf :)?
It is nicer this way, especially if you are stepping through with a debugger.
ACK
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/2387944782fa61a3137afda91e9e8105d8cc5ddf for binaries and test log.