Skip to content

Commit 29f66f7

Browse files
committed
moveonly: move SetSocketNonBlocking() from netbase to util/sock
To be converted to a method of the `Sock` class.
1 parent b4bac55 commit 29f66f7

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/netbase.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -717,21 +717,6 @@ bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
717717
return false;
718718
}
719719

720-
bool SetSocketNonBlocking(const SOCKET& hSocket)
721-
{
722-
#ifdef WIN32
723-
u_long nOne = 1;
724-
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
725-
#else
726-
int fFlags = fcntl(hSocket, F_GETFL, 0);
727-
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
728-
#endif
729-
return false;
730-
}
731-
732-
return true;
733-
}
734-
735720
void InterruptSocks5(bool interrupt)
736721
{
737722
interruptSocks5Recv = interrupt;

src/netbase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
221221
*/
222222
bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed);
223223

224-
/** Enable non-blocking mode for a socket */
225-
bool SetSocketNonBlocking(const SOCKET& hSocket);
226224
void InterruptSocks5(bool interrupt);
227225

228226
/**

src/util/sock.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ int Sock::GetSockName(sockaddr* name, socklen_t* name_len) const
117117
return getsockname(m_socket, name, name_len);
118118
}
119119

120+
bool SetSocketNonBlocking(const SOCKET& hSocket)
121+
{
122+
#ifdef WIN32
123+
u_long nOne = 1;
124+
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
125+
#else
126+
int fFlags = fcntl(hSocket, F_GETFL, 0);
127+
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
128+
#endif
129+
return false;
130+
}
131+
132+
return true;
133+
}
134+
120135
bool Sock::IsSelectable() const
121136
{
122137
#if defined(USE_POLL) || defined(WIN32)

src/util/sock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class Sock
273273
void Close();
274274
};
275275

276+
/** Enable non-blocking mode for a socket */
277+
bool SetSocketNonBlocking(const SOCKET& hSocket);
278+
276279
/** Return readable error string for a network error code */
277280
std::string NetworkErrorString(int err);
278281

0 commit comments

Comments
 (0)