Skip to content

Commit 3830b6e

Browse files
committed
net: use CreateSocket for binds
1 parent df3bcf8 commit 3830b6e

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

src/net.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,44 +2078,21 @@ bool CConnman::BindListenPort(const CService &addrBind, std::string& strError, b
20782078
return false;
20792079
}
20802080

2081-
SOCKET hListenSocket = socket(((struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
2081+
SOCKET hListenSocket = CreateSocket(addrBind);
20822082
if (hListenSocket == INVALID_SOCKET)
20832083
{
20842084
strError = strprintf("Error: Couldn't open socket for incoming connections (socket returned error %s)", NetworkErrorString(WSAGetLastError()));
20852085
LogPrintf("%s\n", strError);
20862086
return false;
20872087
}
2088-
if (!IsSelectableSocket(hListenSocket))
2089-
{
2090-
strError = "Error: Couldn't create a listenable socket for incoming connections";
2091-
LogPrintf("%s\n", strError);
2092-
return false;
2093-
}
2094-
2095-
20962088
#ifndef WIN32
2097-
#ifdef SO_NOSIGPIPE
2098-
// Different way of disabling SIGPIPE on BSD
2099-
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
2100-
#endif
21012089
// Allow binding if the port is still in TIME_WAIT state after
21022090
// the program was closed and restarted.
21032091
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
2104-
// Disable Nagle's algorithm
2105-
setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&nOne, sizeof(int));
21062092
#else
21072093
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&nOne, sizeof(int));
2108-
setsockopt(hListenSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&nOne, sizeof(int));
21092094
#endif
21102095

2111-
// Set to non-blocking, incoming connections will also inherit this
2112-
if (!SetSocketNonBlocking(hListenSocket, true)) {
2113-
CloseSocket(hListenSocket);
2114-
strError = strprintf("BindListenPort: Setting listening socket to non-blocking failed, error %s\n", NetworkErrorString(WSAGetLastError()));
2115-
LogPrintf("%s\n", strError);
2116-
return false;
2117-
}
2118-
21192096
// some systems don't have IPV6_V6ONLY but are always v6only; others do have the option
21202097
// and enable it by default or not. Try to enable it, if possible.
21212098
if (addrBind.IsIPv6()) {

0 commit comments

Comments
 (0)