aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-07-09 18:23:27 -0400
committerWladimir J. van der Laan <laanwj@gmail.com>2015-07-20 17:29:44 +0200
commit0739e6e57a4b59966588a79ac2646eb3264c4dfa (patch)
tree02ba47d716ca8ec4da6edbd7a28953d4c049957d /src/net.cpp
parent255eced936a484de1ce3b5ef6893327b92df0a93 (diff)
downloadbitcoin-0739e6e57a4b59966588a79ac2646eb3264c4dfa.tar.xz
Test whether created sockets are select()able
Conflicts: src/net.cpp Github-Pull: #6412 Rebased-From: d422f9b1fdb42a51aadaa1bbc157542dca2feb17
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 47221edef6..6eb2020b33 100644
--- a/src/net.cpp
+++ b/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