mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
net: check for invalid socket earlier in CConnman::AcceptConnection()
This check is related to an `accept()` failure. So do the check earlier, closer to the `accept()` call. This will allow to isolate the `accept()`-specific code at the beginning of `CConnman::AcceptConnection()` and reuse the code that follows it.
This commit is contained in:
parent
545bc5f81d
commit
25605895af
1 changed files with 9 additions and 11 deletions
20
src/net.cpp
20
src/net.cpp
|
@ -1008,10 +1008,16 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
|
||||||
int nInbound = 0;
|
int nInbound = 0;
|
||||||
int nMaxInbound = nMaxConnections - m_max_outbound;
|
int nMaxInbound = nMaxConnections - m_max_outbound;
|
||||||
|
|
||||||
if (hSocket != INVALID_SOCKET) {
|
if (hSocket == INVALID_SOCKET) {
|
||||||
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) {
|
const int nErr = WSAGetLastError();
|
||||||
LogPrintf("Warning: Unknown socket family\n");
|
if (nErr != WSAEWOULDBLOCK) {
|
||||||
|
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) {
|
||||||
|
LogPrintf("Warning: Unknown socket family\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
NetPermissionFlags permissionFlags = NetPermissionFlags::PF_NONE;
|
NetPermissionFlags permissionFlags = NetPermissionFlags::PF_NONE;
|
||||||
|
@ -1032,14 +1038,6 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hSocket == INVALID_SOCKET)
|
|
||||||
{
|
|
||||||
int nErr = WSAGetLastError();
|
|
||||||
if (nErr != WSAEWOULDBLOCK)
|
|
||||||
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fNetworkActive) {
|
if (!fNetworkActive) {
|
||||||
LogPrint(BCLog::NET, "connection from %s dropped: not accepting new connections\n", addr.ToString());
|
LogPrint(BCLog::NET, "connection from %s dropped: not accepting new connections\n", addr.ToString());
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
|
|
Loading…
Add table
Reference in a new issue