Skip to content

Commit 9e3b2f5

Browse files
committed
net: Move IsSelectableSocket check into socket creation
We use select in ConnectSocketDirectly, so this check needs to happen before that. IsSelectableSocket will not be relevant after upcoming changes to remove select.
1 parent 1729c29 commit 9e3b2f5

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/net.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,19 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
446446
SplitHostPort(std::string(pszDest), port, host);
447447
connected = ConnectThroughProxy(proxy, host, port, hSocket, nConnectTimeout, nullptr);
448448
}
449-
if (connected) {
450-
if (!IsSelectableSocket(hSocket)) {
451-
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
452-
CloseSocket(hSocket);
453-
return nullptr;
454-
}
455-
456-
// Add node
457-
NodeId id = GetNewNodeId();
458-
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
459-
CAddress addr_bind = GetBindAddress(hSocket);
460-
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", false);
461-
pnode->AddRef();
462-
463-
return pnode;
449+
if (!connected) {
450+
CloseSocket(hSocket);
451+
return nullptr;
464452
}
465453

466-
return nullptr;
454+
// Add node
455+
NodeId id = GetNewNodeId();
456+
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
457+
CAddress addr_bind = GetBindAddress(hSocket);
458+
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", false);
459+
pnode->AddRef();
460+
461+
return pnode;
467462
}
468463

469464
void CConnman::DumpBanlist()

src/netbase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,12 @@ SOCKET CreateSocket(const CService &addrConnect)
465465
if (hSocket == INVALID_SOCKET)
466466
return INVALID_SOCKET;
467467

468+
if (!IsSelectableSocket(hSocket)) {
469+
CloseSocket(hSocket);
470+
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
471+
return INVALID_SOCKET;
472+
}
473+
468474
#ifdef SO_NOSIGPIPE
469475
int set = 1;
470476
// Different way of disabling SIGPIPE on BSD

0 commit comments

Comments
 (0)