aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2022-07-05 12:20:42 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-07-20 16:26:24 +0200
commit29f66f76826056f53d971ac734b7ed49b39848d3 (patch)
tree6bb5fe27880dc8c584ce7297afdbc654610975a7
parentb4bac556791b5bb8aa118d4c1fed42c3fe45550c (diff)
moveonly: move SetSocketNonBlocking() from netbase to util/sock
To be converted to a method of the `Sock` class.
-rw-r--r--src/netbase.cpp15
-rw-r--r--src/netbase.h2
-rw-r--r--src/util/sock.cpp15
-rw-r--r--src/util/sock.h3
4 files changed, 18 insertions, 17 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 22cf4415c8..b13d6b1ae0 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -717,21 +717,6 @@ bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
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)
{
interruptSocks5Recv = interrupt;
diff --git a/src/netbase.h b/src/netbase.h
index fadc8b418e..f7816f5d1d 100644
--- a/src/netbase.h
+++ b/src/netbase.h
@@ -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);
-/** Enable non-blocking mode for a socket */
-bool SetSocketNonBlocking(const SOCKET& hSocket);
void InterruptSocks5(bool interrupt);
/**
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index c312a88276..b2b5133629 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -117,6 +117,21 @@ int Sock::GetSockName(sockaddr* name, socklen_t* name_len) const
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
{
#if defined(USE_POLL) || defined(WIN32)
diff --git a/src/util/sock.h b/src/util/sock.h
index ab9c6737c6..b97977da95 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -273,6 +273,9 @@ private:
void Close();
};
+/** Enable non-blocking mode for a socket */
+bool SetSocketNonBlocking(const SOCKET& hSocket);
+
/** Return readable error string for a network error code */
std::string NetworkErrorString(int err);