Skip to content

Commit b69fd5e

Browse files
committed
Merge bitcoin/bitcoin#22052: net: remove non-blocking bool from interface
c71117f net: remove non-blocking bool from interface (Bushstar) Pull request description: SetSocketNonBlocking was added in 0.11 in the PR below with a second argument to toggle non-blocking mode for the socket. That argument has always been set to true in all subsequent releases and I'm not sure why it is present. bitcoin/bitcoin#4491 ACKs for top commit: promag: Code review ACK c71117f. lsilva01: Code review ACK bitcoin/bitcoin@c71117f vasild: ACK c71117f Tree-SHA512: feebfcfa75d997460a0ba42ffe1e0c25a7e0bfcad12510ad73ea4942cc1c653f9ad429adbbb00b9288fe319009552906fcb635a14dfd7dcbde3853baab6be065
2 parents 1e3ed01 + c71117f commit b69fd5e

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

src/netbase.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ enum class IntrRecvError {
305305
*
306306
* @see This function can be interrupted by calling InterruptSocks5(bool).
307307
* Sockets can be made non-blocking with SetSocketNonBlocking(const
308-
* SOCKET&, bool).
308+
* SOCKET&).
309309
*/
310310
static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, const Sock& sock)
311311
{
@@ -518,7 +518,7 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
518518
SetSocketNoDelay(hSocket);
519519

520520
// Set the non-blocking option on the socket.
521-
if (!SetSocketNonBlocking(hSocket, true)) {
521+
if (!SetSocketNonBlocking(hSocket)) {
522522
CloseSocket(hSocket);
523523
LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
524524
return nullptr;
@@ -711,28 +711,16 @@ bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
711711
return false;
712712
}
713713

714-
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking)
714+
bool SetSocketNonBlocking(const SOCKET& hSocket)
715715
{
716-
if (fNonBlocking) {
717716
#ifdef WIN32
718-
u_long nOne = 1;
719-
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
717+
u_long nOne = 1;
718+
if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) {
720719
#else
721-
int fFlags = fcntl(hSocket, F_GETFL, 0);
722-
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
720+
int fFlags = fcntl(hSocket, F_GETFL, 0);
721+
if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == SOCKET_ERROR) {
723722
#endif
724-
return false;
725-
}
726-
} else {
727-
#ifdef WIN32
728-
u_long nZero = 0;
729-
if (ioctlsocket(hSocket, FIONBIO, &nZero) == SOCKET_ERROR) {
730-
#else
731-
int fFlags = fcntl(hSocket, F_GETFL, 0);
732-
if (fcntl(hSocket, F_SETFL, fFlags & ~O_NONBLOCK) == SOCKET_ERROR) {
733-
#endif
734-
return false;
735-
}
723+
return false;
736724
}
737725

738726
return true;

src/netbase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ 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-
/** Disable or enable blocking-mode for a socket */
225-
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
224+
/** Enable non-blocking mode for a socket */
225+
bool SetSocketNonBlocking(const SOCKET& hSocket);
226226
/** Set the TCP_NODELAY flag on a socket */
227227
bool SetSocketNoDelay(const SOCKET& hSocket);
228228
void InterruptSocks5(bool interrupt);

0 commit comments

Comments
 (0)