mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-23 05:14:19 +00:00
net: make proxy receives interruptible
This commit is contained in:
parent
5cb0fcee81
commit
8b3159ef0a
@ -2157,6 +2157,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
|
|||||||
//
|
//
|
||||||
// Start threads
|
// Start threads
|
||||||
//
|
//
|
||||||
|
InterruptSocks5(false);
|
||||||
interruptNet.reset();
|
interruptNet.reset();
|
||||||
flagInterruptMsgProc = false;
|
flagInterruptMsgProc = false;
|
||||||
|
|
||||||
@ -2208,6 +2209,7 @@ void CConnman::Interrupt()
|
|||||||
condMsgProc.notify_all();
|
condMsgProc.notify_all();
|
||||||
|
|
||||||
interruptNet();
|
interruptNet();
|
||||||
|
InterruptSocks5(true);
|
||||||
|
|
||||||
if (semOutbound)
|
if (semOutbound)
|
||||||
for (int i=0; i<(nMaxOutbound + nMaxFeeler); i++)
|
for (int i=0; i<(nMaxOutbound + nMaxFeeler); i++)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifdef HAVE_GETADDRINFO_A
|
#ifdef HAVE_GETADDRINFO_A
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#if HAVE_INET_PTON
|
#if HAVE_INET_PTON
|
||||||
@ -44,6 +45,7 @@ bool fNameLookup = DEFAULT_NAME_LOOKUP;
|
|||||||
|
|
||||||
// Need ample time for negotiation for very slow proxies such as Tor (milliseconds)
|
// Need ample time for negotiation for very slow proxies such as Tor (milliseconds)
|
||||||
static const int SOCKS5_RECV_TIMEOUT = 20 * 1000;
|
static const int SOCKS5_RECV_TIMEOUT = 20 * 1000;
|
||||||
|
static std::atomic<bool> interruptSocks5Recv(false);
|
||||||
|
|
||||||
enum Network ParseNetwork(std::string net) {
|
enum Network ParseNetwork(std::string net) {
|
||||||
boost::to_lower(net);
|
boost::to_lower(net);
|
||||||
@ -206,7 +208,7 @@ struct timeval MillisToTimeval(int64_t nTimeout)
|
|||||||
/**
|
/**
|
||||||
* Read bytes from socket. This will either read the full number of bytes requested
|
* Read bytes from socket. This will either read the full number of bytes requested
|
||||||
* or return False on error or timeout.
|
* or return False on error or timeout.
|
||||||
* This function can be interrupted by boost thread interrupt.
|
* This function can be interrupted by calling InterruptSocks5()
|
||||||
*
|
*
|
||||||
* @param data Buffer to receive into
|
* @param data Buffer to receive into
|
||||||
* @param len Length of data to receive
|
* @param len Length of data to receive
|
||||||
@ -246,7 +248,8 @@ bool static InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSock
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boost::this_thread::interruption_point();
|
if (interruptSocks5Recv)
|
||||||
|
return false;
|
||||||
curTime = GetTimeMillis();
|
curTime = GetTimeMillis();
|
||||||
}
|
}
|
||||||
return len == 0;
|
return len == 0;
|
||||||
@ -715,3 +718,8 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InterruptSocks5(bool interrupt)
|
||||||
|
{
|
||||||
|
interruptSocks5Recv = interrupt;
|
||||||
|
}
|
||||||
|
@ -63,5 +63,6 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking);
|
|||||||
* Convert milliseconds to a struct timeval for e.g. select.
|
* Convert milliseconds to a struct timeval for e.g. select.
|
||||||
*/
|
*/
|
||||||
struct timeval MillisToTimeval(int64_t nTimeout);
|
struct timeval MillisToTimeval(int64_t nTimeout);
|
||||||
|
void InterruptSocks5(bool interrupt);
|
||||||
|
|
||||||
#endif // BITCOIN_NETBASE_H
|
#endif // BITCOIN_NETBASE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user