|
|
|
@ -203,7 +203,7 @@ enum class IntrRecvError {
|
|
|
|
|
*
|
|
|
|
|
* @note This function requires that hSocket is in non-blocking mode.
|
|
|
|
|
*/
|
|
|
|
|
static IntrRecvError InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSocket)
|
|
|
|
|
static IntrRecvError InterruptibleRecv(char* data, size_t len, int timeout, const SOCKET& hSocket)
|
|
|
|
|
{
|
|
|
|
|
int64_t curTime = GetTimeMillis();
|
|
|
|
|
int64_t endTime = curTime + timeout;
|
|
|
|
@ -424,8 +424,10 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
|
|
|
|
|
SetSocketNoDelay(hSocket);
|
|
|
|
|
|
|
|
|
|
// Set to non-blocking
|
|
|
|
|
if (!SetSocketNonBlocking(hSocket, true))
|
|
|
|
|
if (!SetSocketNonBlocking(hSocket, true)) {
|
|
|
|
|
CloseSocket(hSocket);
|
|
|
|
|
return error("ConnectSocketDirectly: Setting socket to non-blocking failed, error %s\n", NetworkErrorString(WSAGetLastError()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (connect(hSocket, (struct sockaddr*)&sockaddr, len) == SOCKET_ERROR)
|
|
|
|
|
{
|
|
|
|
@ -682,7 +684,7 @@ bool CloseSocket(SOCKET& hSocket)
|
|
|
|
|
return ret != SOCKET_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
|
|
|
|
|
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking)
|
|
|
|
|
{
|
|
|
|
|
if (fNonBlocking) {
|
|
|
|
|
#ifdef WIN32
|
|
|
|
@ -692,7 +694,6 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
|
|
|
|
|
int fFlags = fcntl(hSocket, F_GETFL, 0);
|
|
|
|
|
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
|
|
|
|
|
#endif
|
|
|
|
|
CloseSocket(hSocket);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -703,7 +704,6 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
|
|
|
|
|
int fFlags = fcntl(hSocket, F_GETFL, 0);
|
|
|
|
|
if (fcntl(hSocket, F_SETFL, fFlags & ~O_NONBLOCK) == SOCKET_ERROR) {
|
|
|
|
|
#endif
|
|
|
|
|
CloseSocket(hSocket);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -711,7 +711,7 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SetSocketNoDelay(SOCKET& hSocket)
|
|
|
|
|
bool SetSocketNoDelay(const SOCKET& hSocket)
|
|
|
|
|
{
|
|
|
|
|
int set = 1;
|
|
|
|
|
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
|
|
|
|
|