File tree Expand file tree Collapse file tree 3 files changed +15
-21
lines changed Expand file tree Collapse file tree 3 files changed +15
-21
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
24
24
FuzzedSock::~FuzzedSock ()
25
25
{
26
26
// Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
27
- // Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket (m_socket).
27
+ // Sock::Reset() (not FuzzedSock::Reset()!) which will call close (m_socket).
28
28
// Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which
29
29
// theoretically may concide with a real opened file descriptor).
30
30
Reset ();
Original file line number Diff line number Diff line change @@ -51,7 +51,20 @@ Sock& Sock::operator=(Sock&& other)
51
51
52
52
SOCKET Sock::Get () const { return m_socket; }
53
53
54
- void Sock::Reset () { CloseSocket (m_socket); }
54
+ void Sock::Reset () {
55
+ if (m_socket == INVALID_SOCKET) {
56
+ return ;
57
+ }
58
+ #ifdef WIN32
59
+ int ret = closesocket (m_socket);
60
+ #else
61
+ int ret = close (m_socket);
62
+ #endif
63
+ if (ret) {
64
+ LogPrintf (" Error closing socket %d: %s\n " , m_socket, NetworkErrorString (WSAGetLastError ()));
65
+ }
66
+ m_socket = INVALID_SOCKET;
67
+ }
55
68
56
69
ssize_t Sock::Send (const void * data, size_t len, int flags) const
57
70
{
@@ -382,19 +395,3 @@ std::string NetworkErrorString(int err)
382
395
return SysErrorString (err);
383
396
}
384
397
#endif
385
-
386
- bool CloseSocket (SOCKET& hSocket)
387
- {
388
- if (hSocket == INVALID_SOCKET)
389
- return false ;
390
- #ifdef WIN32
391
- int ret = closesocket (hSocket);
392
- #else
393
- int ret = close (hSocket);
394
- #endif
395
- if (ret) {
396
- LogPrintf (" Socket close failed: %d. Error: %s\n " , hSocket, NetworkErrorString (WSAGetLastError ()));
397
- }
398
- hSocket = INVALID_SOCKET;
399
- return ret != SOCKET_ERROR;
400
- }
Original file line number Diff line number Diff line change @@ -250,7 +250,4 @@ class Sock
250
250
/* * Return readable error string for a network error code */
251
251
std::string NetworkErrorString (int err);
252
252
253
- /* * Close socket and set hSocket to INVALID_SOCKET */
254
- bool CloseSocket (SOCKET& hSocket);
255
-
256
253
#endif // BITCOIN_UTIL_SOCK_H
You can’t perform that action at this time.
0 commit comments