Skip to content

Commit

Permalink
net: Move IsSelectableSocket check into socket creation
Browse files Browse the repository at this point in the history
We use select in ConnectSocketDirectly, so this check needs to happen before
that.

IsSelectableSocket will not be relevant after upcoming changes to remove select.
  • Loading branch information
theuni committed Dec 12, 2017
1 parent 1729c29 commit 9e3b2f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,24 +446,19 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
SplitHostPort(std::string(pszDest), port, host);
connected = ConnectThroughProxy(proxy, host, port, hSocket, nConnectTimeout, nullptr);
}
if (connected) {
if (!IsSelectableSocket(hSocket)) {
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
CloseSocket(hSocket);
return nullptr;
}

// Add node
NodeId id = GetNewNodeId();
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
CAddress addr_bind = GetBindAddress(hSocket);
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", false);
pnode->AddRef();

return pnode;
if (!connected) {
CloseSocket(hSocket);
return nullptr;
}

return nullptr;
// Add node
NodeId id = GetNewNodeId();
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
CAddress addr_bind = GetBindAddress(hSocket);
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", false);
pnode->AddRef();

return pnode;
}

void CConnman::DumpBanlist()
Expand Down
6 changes: 6 additions & 0 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ SOCKET CreateSocket(const CService &addrConnect)
if (hSocket == INVALID_SOCKET)
return INVALID_SOCKET;

if (!IsSelectableSocket(hSocket)) {
CloseSocket(hSocket);
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
return INVALID_SOCKET;
}

#ifdef SO_NOSIGPIPE
int set = 1;
// Different way of disabling SIGPIPE on BSD
Expand Down

0 comments on commit 9e3b2f5

Please sign in to comment.