mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-01 23:12:33 +02:00
net: use Sock::SetSockOpt() instead of setsockopt()
This commit is contained in:
parent
184e56d668
commit
d65b6c3fb9
15
src/net.cpp
15
src/net.cpp
@ -2395,17 +2395,26 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
|
|||||||
|
|
||||||
// Allow binding if the port is still in TIME_WAIT state after
|
// Allow binding if the port is still in TIME_WAIT state after
|
||||||
// the program was closed and restarted.
|
// the program was closed and restarted.
|
||||||
setsockopt(sock->Get(), SOL_SOCKET, SO_REUSEADDR, (sockopt_arg_type)&nOne, sizeof(int));
|
if (sock->SetSockOpt(SOL_SOCKET, SO_REUSEADDR, (sockopt_arg_type)&nOne, sizeof(int)) == SOCKET_ERROR) {
|
||||||
|
strError = strprintf(Untranslated("Error setting SO_REUSEADDR on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
|
||||||
|
LogPrintf("%s\n", strError.original);
|
||||||
|
}
|
||||||
|
|
||||||
// some systems don't have IPV6_V6ONLY but are always v6only; others do have the option
|
// some systems don't have IPV6_V6ONLY but are always v6only; others do have the option
|
||||||
// and enable it by default or not. Try to enable it, if possible.
|
// and enable it by default or not. Try to enable it, if possible.
|
||||||
if (addrBind.IsIPv6()) {
|
if (addrBind.IsIPv6()) {
|
||||||
#ifdef IPV6_V6ONLY
|
#ifdef IPV6_V6ONLY
|
||||||
setsockopt(sock->Get(), IPPROTO_IPV6, IPV6_V6ONLY, (sockopt_arg_type)&nOne, sizeof(int));
|
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_V6ONLY, (sockopt_arg_type)&nOne, sizeof(int)) == SOCKET_ERROR) {
|
||||||
|
strError = strprintf(Untranslated("Error setting IPV6_V6ONLY on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
|
||||||
|
LogPrintf("%s\n", strError.original);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
|
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
|
||||||
setsockopt(sock->Get(), IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int));
|
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)) == SOCKET_ERROR) {
|
||||||
|
strError = strprintf(Untranslated("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
|
||||||
|
LogPrintf("%s\n", strError.original);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,10 +499,11 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto sock = std::make_unique<Sock>(hSocket);
|
||||||
|
|
||||||
// Ensure that waiting for I/O on this socket won't result in undefined
|
// Ensure that waiting for I/O on this socket won't result in undefined
|
||||||
// behavior.
|
// behavior.
|
||||||
if (!IsSelectableSocket(hSocket)) {
|
if (!IsSelectableSocket(sock->Get())) {
|
||||||
CloseSocket(hSocket);
|
|
||||||
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
|
LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -511,19 +512,21 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
|
|||||||
int set = 1;
|
int set = 1;
|
||||||
// Set the no-sigpipe option on the socket for BSD systems, other UNIXes
|
// Set the no-sigpipe option on the socket for BSD systems, other UNIXes
|
||||||
// should use the MSG_NOSIGNAL flag for every send.
|
// 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
|
#endif
|
||||||
|
|
||||||
// Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
|
// 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.
|
// Set the non-blocking option on the socket.
|
||||||
if (!SetSocketNonBlocking(hSocket)) {
|
if (!SetSocketNonBlocking(sock->Get())) {
|
||||||
CloseSocket(hSocket);
|
|
||||||
LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
|
LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::make_unique<Sock>(hSocket);
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<std::unique_ptr<Sock>(const CService&)> CreateSock = CreateSockTCP;
|
std::function<std::unique_ptr<Sock>(const CService&)> CreateSock = CreateSockTCP;
|
||||||
|
Loading…
Reference in New Issue
Block a user