mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
moved netdb requests to separate thread
This commit is contained in:
@@ -104,15 +104,37 @@ namespace data
|
||||
}
|
||||
}
|
||||
|
||||
NetDbRequests::NetDbRequests ():
|
||||
RunnableServiceWithWork ("NetDbReq"),
|
||||
m_ManageRequestsTimer (GetIOService ())
|
||||
{
|
||||
}
|
||||
|
||||
NetDbRequests::~NetDbRequests ()
|
||||
{
|
||||
Stop ();
|
||||
}
|
||||
|
||||
void NetDbRequests::Start ()
|
||||
{
|
||||
m_LastPoolCleanUpTime = i2p::util::GetSecondsSinceEpoch ();
|
||||
if (!IsRunning ())
|
||||
{
|
||||
StartIOService ();
|
||||
ScheduleManageRequests ();
|
||||
}
|
||||
}
|
||||
|
||||
void NetDbRequests::Stop ()
|
||||
{
|
||||
m_RequestedDestinations.clear ();
|
||||
m_RequestedDestinationsPool.CleanUpMt ();
|
||||
if (IsRunning ())
|
||||
{
|
||||
m_ManageRequestsTimer.cancel ();
|
||||
StopIOService ();
|
||||
|
||||
m_RequestedDestinations.clear ();
|
||||
m_RequestedDestinationsPool.CleanUpMt ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -294,5 +316,22 @@ namespace data
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void NetDbRequests::ScheduleManageRequests ()
|
||||
{
|
||||
m_ManageRequestsTimer.expires_from_now (boost::posix_time::seconds(MANAGE_REQUESTS_INTERVAL));
|
||||
m_ManageRequestsTimer.async_wait (std::bind (&NetDbRequests::HandleManageRequestsTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void NetDbRequests::HandleManageRequestsTimer (const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
if (i2p::tunnel::tunnels.GetExploratoryPool ()) // expolratory pool is ready?
|
||||
ManageRequests ();
|
||||
ScheduleManageRequests ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user