mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Convert closesocket 'compat wrapper' to function in netbase
Simpler alternative to #4348. The current setup with closesocket() is strange. It poses as a compatibility wrapper but adds functionality. Rename it and make it a documented utility function in netbase. Code movement only, zero effect on the functionality.
This commit is contained in:
19
src/net.cpp
19
src/net.cpp
@@ -332,7 +332,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
|
||||
{
|
||||
if (!RecvLine(hSocket, strLine))
|
||||
{
|
||||
closesocket(hSocket);
|
||||
CloseSocket(hSocket);
|
||||
return false;
|
||||
}
|
||||
if (pszKeyword == NULL)
|
||||
@@ -343,7 +343,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
|
||||
break;
|
||||
}
|
||||
}
|
||||
closesocket(hSocket);
|
||||
CloseSocket(hSocket);
|
||||
if (strLine.find("<") != string::npos)
|
||||
strLine = strLine.substr(0, strLine.find("<"));
|
||||
strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r"));
|
||||
@@ -357,7 +357,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
|
||||
return true;
|
||||
}
|
||||
}
|
||||
closesocket(hSocket);
|
||||
CloseSocket(hSocket);
|
||||
return error("GetMyExternalIP() : connection closed");
|
||||
}
|
||||
|
||||
@@ -533,8 +533,7 @@ void CNode::CloseSocketDisconnect()
|
||||
if (hSocket != INVALID_SOCKET)
|
||||
{
|
||||
LogPrint("net", "disconnecting peer=%d\n", id);
|
||||
closesocket(hSocket);
|
||||
hSocket = INVALID_SOCKET;
|
||||
CloseSocket(hSocket);
|
||||
}
|
||||
|
||||
// in case this fails, we'll empty the recv buffer when the CNode is deleted
|
||||
@@ -975,12 +974,12 @@ void ThreadSocketHandler()
|
||||
}
|
||||
else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
|
||||
{
|
||||
closesocket(hSocket);
|
||||
CloseSocket(hSocket);
|
||||
}
|
||||
else if (CNode::IsBanned(addr) && !whitelisted)
|
||||
{
|
||||
LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
|
||||
closesocket(hSocket);
|
||||
CloseSocket(hSocket);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1817,11 +1816,11 @@ public:
|
||||
// Close sockets
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
if (pnode->hSocket != INVALID_SOCKET)
|
||||
closesocket(pnode->hSocket);
|
||||
CloseSocket(pnode->hSocket);
|
||||
BOOST_FOREACH(ListenSocket& hListenSocket, vhListenSocket)
|
||||
if (hListenSocket.socket != INVALID_SOCKET)
|
||||
if (closesocket(hListenSocket.socket) == SOCKET_ERROR)
|
||||
LogPrintf("closesocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));
|
||||
if (!CloseSocket(hListenSocket.socket))
|
||||
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));
|
||||
|
||||
// clean up some globals (to help leak detection)
|
||||
BOOST_FOREACH(CNode *pnode, vNodes)
|
||||
|
||||
Reference in New Issue
Block a user