mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
net: use Sock::SetSockOpt() instead of setsockopt()
This commit is contained in:
@@ -499,10 +499,11 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto sock = std::make_unique<Sock>(hSocket);
|
||||
|
||||
// Ensure that waiting for I/O on this socket won't result in undefined
|
||||
// behavior.
|
||||
if (!IsSelectableSocket(hSocket)) {
|
||||
CloseSocket(hSocket);
|
||||
if (!IsSelectableSocket(sock->Get())) {
|
||||
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -511,19 +512,21 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
|
||||
int set = 1;
|
||||
// Set the no-sigpipe option on the socket for BSD systems, other UNIXes
|
||||
// should use the MSG_NOSIGNAL flag for every send.
|
||||
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
|
||||
if (sock->SetSockOpt(SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int)) == SOCKET_ERROR) {
|
||||
LogPrintf("Error setting SO_NOSIGPIPE on socket: %s, continuing anyway\n",
|
||||
NetworkErrorString(WSAGetLastError()));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
|
||||
SetSocketNoDelay(hSocket);
|
||||
SetSocketNoDelay(sock->Get());
|
||||
|
||||
// Set the non-blocking option on the socket.
|
||||
if (!SetSocketNonBlocking(hSocket)) {
|
||||
CloseSocket(hSocket);
|
||||
if (!SetSocketNonBlocking(sock->Get())) {
|
||||
LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<Sock>(hSocket);
|
||||
return sock;
|
||||
}
|
||||
|
||||
std::function<std::unique_ptr<Sock>(const CService&)> CreateSock = CreateSockTCP;
|
||||
|
||||
Reference in New Issue
Block a user