Changeset View
Changeset View
Standalone View
Standalone View
src/netbase.cpp
Show First 20 Lines • Show All 478 Lines • ▼ Show 20 Lines | if (!IsSelectableSocket(hSocket)) { | ||||
LogPrintf("Cannot create connection: non-selectable socket created (fd " | LogPrintf("Cannot create connection: non-selectable socket created (fd " | ||||
">= FD_SETSIZE ?)\n"); | ">= FD_SETSIZE ?)\n"); | ||||
return INVALID_SOCKET; | return INVALID_SOCKET; | ||||
} | } | ||||
#ifdef SO_NOSIGPIPE | #ifdef SO_NOSIGPIPE | ||||
int set = 1; | int set = 1; | ||||
// Different way of disabling SIGPIPE on BSD | // Different way of disabling SIGPIPE on BSD | ||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)); | setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (sockopt_arg_type)&set, | ||||
sizeof(int)); | |||||
#endif | #endif | ||||
// Disable Nagle's algorithm | // Disable Nagle's algorithm | ||||
SetSocketNoDelay(hSocket); | SetSocketNoDelay(hSocket); | ||||
// Set to non-blocking | // Set to non-blocking | ||||
if (!SetSocketNonBlocking(hSocket, true)) { | if (!SetSocketNonBlocking(hSocket, true)) { | ||||
CloseSocket(hSocket); | CloseSocket(hSocket); | ||||
Show All 35 Lines | if (connect(hSocket, (struct sockaddr *)&sockaddr, len) == SOCKET_ERROR) { | ||||
} | } | ||||
if (nRet == SOCKET_ERROR) { | if (nRet == SOCKET_ERROR) { | ||||
LogPrintf("select() for %s failed: %s\n", | LogPrintf("select() for %s failed: %s\n", | ||||
addrConnect.ToString(), | addrConnect.ToString(), | ||||
NetworkErrorString(WSAGetLastError())); | NetworkErrorString(WSAGetLastError())); | ||||
return false; | return false; | ||||
} | } | ||||
socklen_t nRetSize = sizeof(nRet); | socklen_t nRetSize = sizeof(nRet); | ||||
#ifdef WIN32 | if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, | ||||
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char *)(&nRet), | (sockopt_arg_type)&nRet, | ||||
&nRetSize) == SOCKET_ERROR) | &nRetSize) == SOCKET_ERROR) { | ||||
#else | |||||
if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == | |||||
SOCKET_ERROR) | |||||
#endif | |||||
{ | |||||
LogPrintf("getsockopt() for %s failed: %s\n", | LogPrintf("getsockopt() for %s failed: %s\n", | ||||
addrConnect.ToString(), | addrConnect.ToString(), | ||||
NetworkErrorString(WSAGetLastError())); | NetworkErrorString(WSAGetLastError())); | ||||
return false; | return false; | ||||
} | } | ||||
if (nRet != 0) { | if (nRet != 0) { | ||||
LogPrintf("connect() to %s failed after select(): %s\n", | LogPrintf("connect() to %s failed after select(): %s\n", | ||||
addrConnect.ToString(), NetworkErrorString(nRet)); | addrConnect.ToString(), NetworkErrorString(nRet)); | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | #endif | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool SetSocketNoDelay(const SOCKET &hSocket) { | bool SetSocketNoDelay(const SOCKET &hSocket) { | ||||
int set = 1; | int set = 1; | ||||
int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&set, | int rc = setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, | ||||
sizeof(int)); | (sockopt_arg_type)&set, sizeof(int)); | ||||
return rc == 0; | return rc == 0; | ||||
} | } | ||||
void InterruptSocks5(bool interrupt) { | void InterruptSocks5(bool interrupt) { | ||||
interruptSocks5Recv = interrupt; | interruptSocks5Recv = interrupt; | ||||
} | } |