Skip to content

Commit 8b3159e

Browse files
committed
net: make proxy receives interruptible
1 parent 5cb0fce commit 8b3159e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/net.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
21572157
//
21582158
// Start threads
21592159
//
2160+
InterruptSocks5(false);
21602161
interruptNet.reset();
21612162
flagInterruptMsgProc = false;
21622163

@@ -2208,6 +2209,7 @@ void CConnman::Interrupt()
22082209
condMsgProc.notify_all();
22092210

22102211
interruptNet();
2212+
InterruptSocks5(true);
22112213

22122214
if (semOutbound)
22132215
for (int i=0; i<(nMaxOutbound + nMaxFeeler); i++)

src/netbase.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifdef HAVE_GETADDRINFO_A
2020
#include <netdb.h>
2121
#endif
22+
#include <atomic>
2223

2324
#ifndef WIN32
2425
#if HAVE_INET_PTON
@@ -44,6 +45,7 @@ bool fNameLookup = DEFAULT_NAME_LOOKUP;
4445

4546
// Need ample time for negotiation for very slow proxies such as Tor (milliseconds)
4647
static const int SOCKS5_RECV_TIMEOUT = 20 * 1000;
48+
static std::atomic<bool> interruptSocks5Recv(false);
4749

4850
enum Network ParseNetwork(std::string net) {
4951
boost::to_lower(net);
@@ -206,7 +208,7 @@ struct timeval MillisToTimeval(int64_t nTimeout)
206208
/**
207209
* Read bytes from socket. This will either read the full number of bytes requested
208210
* or return False on error or timeout.
209-
* This function can be interrupted by boost thread interrupt.
211+
* This function can be interrupted by calling InterruptSocks5()
210212
*
211213
* @param data Buffer to receive into
212214
* @param len Length of data to receive
@@ -246,7 +248,8 @@ bool static InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSock
246248
return false;
247249
}
248250
}
249-
boost::this_thread::interruption_point();
251+
if (interruptSocks5Recv)
252+
return false;
250253
curTime = GetTimeMillis();
251254
}
252255
return len == 0;
@@ -715,3 +718,8 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
715718

716719
return true;
717720
}
721+
722+
void InterruptSocks5(bool interrupt)
723+
{
724+
interruptSocks5Recv = interrupt;
725+
}

src/netbase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking);
6363
* Convert milliseconds to a struct timeval for e.g. select.
6464
*/
6565
struct timeval MillisToTimeval(int64_t nTimeout);
66+
void InterruptSocks5(bool interrupt);
6667

6768
#endif // BITCOIN_NETBASE_H

0 commit comments

Comments
 (0)