@@ -203,7 +203,7 @@ enum class IntrRecvError {
203
203
*
204
204
* @note This function requires that hSocket is in non-blocking mode.
205
205
*/
206
- static IntrRecvError InterruptibleRecv (char * data, size_t len, int timeout, SOCKET& hSocket)
206
+ static IntrRecvError InterruptibleRecv (char * data, size_t len, int timeout, const SOCKET& hSocket)
207
207
{
208
208
int64_t curTime = GetTimeMillis ();
209
209
int64_t endTime = curTime + timeout;
@@ -424,8 +424,10 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
424
424
SetSocketNoDelay (hSocket);
425
425
426
426
// Set to non-blocking
427
- if (!SetSocketNonBlocking (hSocket, true ))
427
+ if (!SetSocketNonBlocking (hSocket, true )) {
428
+ CloseSocket (hSocket);
428
429
return error (" ConnectSocketDirectly: Setting socket to non-blocking failed, error %s\n " , NetworkErrorString (WSAGetLastError ()));
430
+ }
429
431
430
432
if (connect (hSocket, (struct sockaddr *)&sockaddr, len) == SOCKET_ERROR)
431
433
{
@@ -682,7 +684,7 @@ bool CloseSocket(SOCKET& hSocket)
682
684
return ret != SOCKET_ERROR;
683
685
}
684
686
685
- bool SetSocketNonBlocking (SOCKET& hSocket, bool fNonBlocking )
687
+ bool SetSocketNonBlocking (const SOCKET& hSocket, bool fNonBlocking )
686
688
{
687
689
if (fNonBlocking ) {
688
690
#ifdef WIN32
@@ -692,7 +694,6 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
692
694
int fFlags = fcntl (hSocket, F_GETFL, 0 );
693
695
if (fcntl (hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
694
696
#endif
695
- CloseSocket (hSocket);
696
697
return false ;
697
698
}
698
699
} else {
@@ -703,15 +704,14 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
703
704
int fFlags = fcntl (hSocket, F_GETFL, 0 );
704
705
if (fcntl (hSocket, F_SETFL, fFlags & ~O_NONBLOCK) == SOCKET_ERROR) {
705
706
#endif
706
- CloseSocket (hSocket);
707
707
return false ;
708
708
}
709
709
}
710
710
711
711
return true ;
712
712
}
713
713
714
- bool SetSocketNoDelay (SOCKET& hSocket)
714
+ bool SetSocketNoDelay (const SOCKET& hSocket)
715
715
{
716
716
int set = 1 ;
717
717
int rc = setsockopt (hSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&set, sizeof (int ));
0 commit comments