Repository: bitcoin/bitcoin
File: src/netbase.cpp (C++)

Code before:
        }
        }
        if (recvr != IntrRecvError::OK) {
            LogError("Error reading from proxy\n");
            return false;
        }
        if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
            LogError("Error reading from proxy\n");
            return false;
        }
        LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
        return true;
    } catch (const std::runtime_error& e) {
        LogError("Error during SOCKS5 proxy handshake: %s\n", e.what());
        return false;
    }
}

std::unique_ptr<Sock> CreateSockOS(sa_family_t address_family)
{
    // Not IPv4, IPv6 or UNIX
    if (address_family == AF_UNSPEC) return nullptr;

    int protocol{IPPROTO_TCP};
#if HAVE_SOCKADDR_UN
    if (address_family == AF_UNIX) protocol = 0;
#endif

    // Create a socket in the specified address family.
    SOCKET hSocket = socket(address_family, SOCK_STREAM, protocol);
    if (hSocket == INVALID_SOCKET) {
        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 (!sock->IsSelectable()) {
        LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
        return nullptr;
    }

#ifdef SO_NOSIGPIPE
    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.
    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()));
    }

Review comment (suggestion):
Seems ok to remove, since `protocol` is now an argument.

Code after:
        }
        }
        if (recvr != IntrRecvError::OK) {
            LogError("Error reading from proxy\n");
            return false;
        }
        if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
            LogError("Error reading from proxy\n");
            return false;
        }
        LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
        return true;
    } catch (const std::runtime_error& e) {
        LogError("Error during SOCKS5 proxy handshake: %s\n", e.what());
        return false;
    }
}

std::unique_ptr<Sock> CreateSockOS(int domain, int type, int protocol)
{
    // Not IPv4, IPv6 or UNIX
    if (domain == AF_UNSPEC) return nullptr;

    // Create a socket in the specified address family.
    SOCKET hSocket = socket(domain, type, protocol);
    if (hSocket == INVALID_SOCKET) {
        return nullptr;
    }

    auto sock = std::make_unique<Sock>(hSocket);

    if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNIX) {
        return sock;
    }

    // Ensure that waiting for I/O on this socket won't result in undefined
    // behavior.
    if (!sock->IsSelectable()) {
        LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
        return nullptr;
    }

#ifdef SO_NOSIGPIPE
    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.
    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