mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Clean up shutdown process
This commit is contained in:
35
src/net.cpp
35
src/net.cpp
@@ -45,7 +45,6 @@ static bool vfReachable[NET_MAX] = {};
|
||||
static bool vfLimited[NET_MAX] = {};
|
||||
static CNode* pnodeLocalHost = NULL;
|
||||
uint64 nLocalHostNonce = 0;
|
||||
array<int, THREAD_MAX> vnThreadsRunning;
|
||||
static std::vector<SOCKET> vhListenSocket;
|
||||
CAddrMan addrman;
|
||||
|
||||
@@ -147,8 +146,7 @@ bool RecvLine(SOCKET hSocket, string& strLine)
|
||||
}
|
||||
else if (nBytes <= 0)
|
||||
{
|
||||
if (fShutdown)
|
||||
return false;
|
||||
boost::this_thread::interruption_point();
|
||||
if (nBytes < 0)
|
||||
{
|
||||
int nErr = WSAGetLastError();
|
||||
@@ -1775,10 +1773,8 @@ void static Discover()
|
||||
NewThread(ThreadGetMyExternalIP, NULL);
|
||||
}
|
||||
|
||||
void StartNode(void* parg)
|
||||
void StartNode(boost::thread_group& threadGroup)
|
||||
{
|
||||
boost::thread_group* threadGroup = (boost::thread_group*)parg;
|
||||
|
||||
// Make this thread recognisable as the startup thread
|
||||
RenameThread("bitcoin-start");
|
||||
|
||||
@@ -1800,25 +1796,27 @@ void StartNode(void* parg)
|
||||
if (!GetBoolArg("-dnsseed", true))
|
||||
printf("DNS seeding disabled\n");
|
||||
else
|
||||
threadGroup->create_thread(boost::bind(&TraceThread<boost::function<void()> >, "dnsseed", &ThreadDNSAddressSeed));
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<boost::function<void()> >, "dnsseed", &ThreadDNSAddressSeed));
|
||||
|
||||
#ifdef USE_UPNP
|
||||
// Map ports with UPnP
|
||||
MapPort(GetBoolArg("-upnp", USE_UPNP));
|
||||
#endif
|
||||
|
||||
// Send and receive from sockets, accept connections
|
||||
threadGroup->create_thread(boost::bind(&TraceThread<void (*)()>, "net", &ThreadSocketHandler));
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "net", &ThreadSocketHandler));
|
||||
|
||||
// Initiate outbound connections from -addnode
|
||||
threadGroup->create_thread(boost::bind(&TraceThread<void (*)()>, "addcon", &ThreadOpenAddedConnections));
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "addcon", &ThreadOpenAddedConnections));
|
||||
|
||||
// Initiate outbound connections
|
||||
threadGroup->create_thread(boost::bind(&TraceThread<void (*)()>, "opencon", &ThreadOpenConnections));
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "opencon", &ThreadOpenConnections));
|
||||
|
||||
// Process messages
|
||||
threadGroup->create_thread(boost::bind(&TraceThread<void (*)()>, "msghand", &ThreadMessageHandler));
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "msghand", &ThreadMessageHandler));
|
||||
|
||||
// Dump network addresses
|
||||
threadGroup->create_thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 10000));
|
||||
threadGroup.create_thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 10000));
|
||||
}
|
||||
|
||||
bool StopNode()
|
||||
@@ -1826,23 +1824,10 @@ bool StopNode()
|
||||
printf("StopNode()\n");
|
||||
GenerateBitcoins(false, NULL);
|
||||
MapPort(false);
|
||||
fShutdown = true;
|
||||
nTransactionsUpdated++;
|
||||
int64 nStart = GetTime();
|
||||
if (semOutbound)
|
||||
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
|
||||
semOutbound->post();
|
||||
do
|
||||
{
|
||||
int nThreadsRunning = 0;
|
||||
for (int n = 0; n < THREAD_MAX; n++)
|
||||
nThreadsRunning += vnThreadsRunning[n];
|
||||
if (nThreadsRunning == 0)
|
||||
break;
|
||||
if (GetTime() - nStart > 20)
|
||||
break;
|
||||
MilliSleep(20);
|
||||
} while(true);
|
||||
MilliSleep(50);
|
||||
DumpAddresses();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user