mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
moved netdb requests to separate thread
This commit is contained in:
parent
d8707ceb57
commit
e3be409945
3 changed files with 55 additions and 14 deletions
|
@ -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 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue