mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
net: convert standalone SetSocketNonBlocking() to Sock::SetNonBlocking()
This further encapsulates syscalls inside the `Sock` class. Co-authored-by: practicalswift <practicalswift@users.noreply.github.com>
This commit is contained in:
@@ -117,18 +117,22 @@ int Sock::GetSockName(sockaddr* name, socklen_t* name_len) const
|
||||
return getsockname(m_socket, name, name_len);
|
||||
}
|
||||
|
||||
bool SetSocketNonBlocking(const SOCKET& hSocket)
|
||||
bool Sock::SetNonBlocking() const
|
||||
{
|
||||
#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
|
||||
u_long on{1};
|
||||
if (ioctlsocket(m_socket, FIONBIO, &on) == SOCKET_ERROR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
const int flags{fcntl(m_socket, F_GETFL, 0)};
|
||||
if (flags == SOCKET_ERROR) {
|
||||
return false;
|
||||
}
|
||||
if (fcntl(m_socket, F_SETFL, flags | O_NONBLOCK) == SOCKET_ERROR) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user