Test whether created sockets are select()able
Conflicts:
src/net.cpp
Github-Pull: #6412
Rebased-From: d422f9b1fd
This commit is contained in:
parent
255eced936
commit
0739e6e57a
@ -90,4 +90,12 @@ typedef u_int SOCKET;
|
||||
|
||||
size_t strnlen_int( const char *start, size_t max_len);
|
||||
|
||||
bool static inline IsSelectableSocket(SOCKET s) {
|
||||
#ifdef WIN32
|
||||
return true;
|
||||
#else
|
||||
return (s >= 0 && s < FD_SETSIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // BITCOIN_COMPAT_H
|
||||
|
19
src/net.cpp
19
src/net.cpp
@ -403,6 +403,12 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
|
||||
if (pszDest ? ConnectSocketByName(addrConnect, hSocket, pszDest, Params().GetDefaultPort(), nConnectTimeout, &proxyConnectionFailed) :
|
||||
ConnectSocket(addrConnect, hSocket, nConnectTimeout, &proxyConnectionFailed))
|
||||
{
|
||||
if (!IsSelectableSocket(hSocket)) {
|
||||
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
|
||||
CloseSocket(hSocket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
addrman.Attempt(addrConnect);
|
||||
|
||||
// Add node
|
||||
@ -871,8 +877,14 @@ void ThreadSocketHandler()
|
||||
if (nErr != WSAEWOULDBLOCK)
|
||||
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
|
||||
}
|
||||
else if (!IsSelectableSocket(hSocket))
|
||||
{
|
||||
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString());
|
||||
CloseSocket(hSocket);
|
||||
}
|
||||
else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
|
||||
{
|
||||
LogPrint("net", "connection from %s dropped (full)\n", addr.ToString());
|
||||
CloseSocket(hSocket);
|
||||
}
|
||||
else if (CNode::IsBanned(addr) && !whitelisted)
|
||||
@ -1498,6 +1510,13 @@ bool BindListenPort(const CService &addrBind, string& strError, bool fWhiteliste
|
||||
LogPrintf("%s\n", strError);
|
||||
return false;
|
||||
}
|
||||
if (!IsSelectableSocket(hListenSocket))
|
||||
{
|
||||
strError = "Error: Couldn't create a listenable socket for incoming connections";
|
||||
LogPrintf("%s\n", strError);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef SO_NOSIGPIPE
|
||||
|
@ -267,6 +267,9 @@ bool static InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSock
|
||||
} else { // Other error or blocking
|
||||
int nErr = WSAGetLastError();
|
||||
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL) {
|
||||
if (!IsSelectableSocket(hSocket)) {
|
||||
return false;
|
||||
}
|
||||
struct timeval tval = MillisToTimeval(std::min(endTime - curTime, maxWait));
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
|
Loading…
Reference in New Issue
Block a user