aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-07-10 12:13:03 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-07-17 15:46:25 +0200
commit43f510d37d680ca4347878d2fb6f8b97b54e7611 (patch)
tree137cb51c1953826cd595584e8371d5fbd4b2ccb3 /src/net.cpp
parentc4f11ca9c32a90c57bd26eb38e5a264a95baba41 (diff)
downloadbitcoin-43f510d37d680ca4347878d2fb6f8b97b54e7611.tar.xz
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 3b3d91d652..441bde3e90 100644
--- a/src/net.cpp
+++ b/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)