aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2014-07-10 12:13:03 +0200
committerRoss Nicoll <[email protected]>2015-06-27 14:11:36 +0000
commita15d1b4fc1de5c8db28a981314adc69e6aa08c06 (patch)
tree570310acc65f940ef88e48af3f1899c26b5a8495 /src/net.cpp
parentBreak up CAddrMan's IMPLEMENT_SERIALIZE (diff)
downloaddiscoin-a15d1b4fc1de5c8db28a981314adc69e6aa08c06.tar.xz
discoin-a15d1b4fc1de5c8db28a981314adc69e6aa08c06.zip
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.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 779c97952..d4a526cd4 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -336,7 +336,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
{
if (!RecvLine(hSocket, strLine))
{
- closesocket(hSocket);
+ CloseSocket(hSocket);
return false;
}
if (pszKeyword == NULL)
@@ -347,7 +347,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"));
@@ -361,7 +361,7 @@ bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const cha
return true;
}
}
- closesocket(hSocket);
+ CloseSocket(hSocket);
return error("GetMyExternalIP() : connection closed");
}
@@ -522,8 +522,7 @@ void CNode::CloseSocketDisconnect()
if (hSocket != INVALID_SOCKET)
{
LogPrint("net", "disconnecting node %s\n", addrName);
- closesocket(hSocket);
- hSocket = INVALID_SOCKET;
+ CloseSocket(hSocket);
}
// in case this fails, we'll empty the recv buffer when the CNode is deleted
@@ -957,12 +956,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
{
@@ -1813,11 +1812,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)