mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
moveonly: move SetSocketNonBlocking() from netbase to util/sock
To be converted to a method of the `Sock` class.
This commit is contained in:
@@ -717,21 +717,6 @@ bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetSocketNonBlocking(const SOCKET& hSocket)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
u_long nOne = 1;
|
|
||||||
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
|
|
||||||
#else
|
|
||||||
int fFlags = fcntl(hSocket, F_GETFL, 0);
|
|
||||||
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InterruptSocks5(bool interrupt)
|
void InterruptSocks5(bool interrupt)
|
||||||
{
|
{
|
||||||
interruptSocks5Recv = interrupt;
|
interruptSocks5Recv = interrupt;
|
||||||
|
|||||||
@@ -221,8 +221,6 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
|||||||
*/
|
*/
|
||||||
bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);
|
bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);
|
||||||
|
|
||||||
/** Enable non-blocking mode for a socket */
|
|
||||||
bool SetSocketNonBlocking(const SOCKET& hSocket);
|
|
||||||
void InterruptSocks5(bool interrupt);
|
void InterruptSocks5(bool interrupt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -117,6 +117,21 @@ int Sock::GetSockName(sockaddr* name, socklen_t* name_len) const
|
|||||||
return getsockname(m_socket, name, name_len);
|
return getsockname(m_socket, name, name_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SetSocketNonBlocking(const SOCKET& hSocket)
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
u_long nOne = 1;
|
||||||
|
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
|
||||||
|
#else
|
||||||
|
int fFlags = fcntl(hSocket, F_GETFL, 0);
|
||||||
|
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Sock::IsSelectable() const
|
bool Sock::IsSelectable() const
|
||||||
{
|
{
|
||||||
#if defined(USE_POLL) || defined(WIN32)
|
#if defined(USE_POLL) || defined(WIN32)
|
||||||
|
|||||||
@@ -273,6 +273,9 @@ private:
|
|||||||
void Close();
|
void Close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Enable non-blocking mode for a socket */
|
||||||
|
bool SetSocketNonBlocking(const SOCKET& hSocket);
|
||||||
|
|
||||||
/** Return readable error string for a network error code */
|
/** Return readable error string for a network error code */
|
||||||
std::string NetworkErrorString(int err);
|
std::string NetworkErrorString(int err);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user