mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
fix #634.don't create timer in constructor
This commit is contained in:
parent
f9a5f4955c
commit
fbb5bb2f05
|
@ -17,8 +17,7 @@ namespace client
|
||||||
|
|
||||||
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr),
|
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr),
|
||||||
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr),
|
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr),
|
||||||
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr),
|
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr)
|
||||||
m_CleanupUDPTimer(m_Service, boost::posix_time::seconds(1))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,20 +87,9 @@ namespace client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_ServiceThread == nullptr ) {
|
|
||||||
m_ServiceThread = new std::thread([&] () {
|
|
||||||
LogPrint(eLogInfo, "ClientContext: starting service");
|
|
||||||
m_Service.run();
|
|
||||||
LogPrint(eLogError, "ClientContext: service died");
|
|
||||||
});
|
|
||||||
ScheduleCleanupUDP();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// I2P tunnels
|
// I2P tunnels
|
||||||
ReadTunnels ();
|
ReadTunnels ();
|
||||||
|
|
||||||
|
|
||||||
// SAM
|
// SAM
|
||||||
bool sam; i2p::config::GetOption("sam.enabled", sam);
|
bool sam; i2p::config::GetOption("sam.enabled", sam);
|
||||||
if (sam) {
|
if (sam) {
|
||||||
|
@ -149,6 +137,13 @@ namespace client
|
||||||
}
|
}
|
||||||
|
|
||||||
m_AddressBook.StartResolvers ();
|
m_AddressBook.StartResolvers ();
|
||||||
|
|
||||||
|
// start UDP cleanup
|
||||||
|
if (!m_ServerForwards.empty ())
|
||||||
|
{
|
||||||
|
m_CleanupUDPTimer.reset (new boost::asio::deadline_timer(m_SharedLocalDestination->GetService ()));
|
||||||
|
ScheduleCleanupUDP();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::Stop ()
|
void ClientContext::Stop ()
|
||||||
|
@ -210,25 +205,22 @@ namespace client
|
||||||
LogPrint(eLogInfo, "Clients: stopping AddressBook");
|
LogPrint(eLogInfo, "Clients: stopping AddressBook");
|
||||||
m_AddressBook.Stop ();
|
m_AddressBook.Stop ();
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_ForwardsMutex);
|
std::lock_guard<std::mutex> lock(m_ForwardsMutex);
|
||||||
m_ServerForwards.clear();
|
m_ServerForwards.clear();
|
||||||
m_ClientForwards.clear();
|
m_ClientForwards.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_CleanupUDPTimer)
|
||||||
|
{
|
||||||
|
m_CleanupUDPTimer->cancel ();
|
||||||
|
m_CleanupUDPTimer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& it: m_Destinations)
|
for (auto& it: m_Destinations)
|
||||||
it.second->Stop ();
|
it.second->Stop ();
|
||||||
m_Destinations.clear ();
|
m_Destinations.clear ();
|
||||||
m_SharedLocalDestination = nullptr;
|
m_SharedLocalDestination = nullptr;
|
||||||
// stop io service thread
|
|
||||||
if(m_ServiceThread)
|
|
||||||
{
|
|
||||||
m_Service.stop();
|
|
||||||
m_ServiceThread->join();
|
|
||||||
delete m_ServiceThread;
|
|
||||||
m_ServiceThread = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::ReloadConfig ()
|
void ClientContext::ReloadConfig ()
|
||||||
|
@ -558,9 +550,12 @@ namespace client
|
||||||
|
|
||||||
void ClientContext::ScheduleCleanupUDP()
|
void ClientContext::ScheduleCleanupUDP()
|
||||||
{
|
{
|
||||||
// schedule cleanup in 1 second
|
if (m_CleanupUDPTimer)
|
||||||
m_CleanupUDPTimer.expires_at(m_CleanupUDPTimer.expires_at() + boost::posix_time::seconds(1));
|
{
|
||||||
m_CleanupUDPTimer.async_wait(std::bind(&ClientContext::CleanupUDP, this, std::placeholders::_1));
|
// schedule cleanup in 17 seconds
|
||||||
|
m_CleanupUDPTimer->expires_from_now (boost::posix_time::seconds (17));
|
||||||
|
m_CleanupUDPTimer->async_wait(std::bind(&ClientContext::CleanupUDP, this, std::placeholders::_1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientContext::CleanupUDP(const boost::system::error_code & ecode)
|
void ClientContext::CleanupUDP(const boost::system::error_code & ecode)
|
||||||
|
@ -568,7 +563,7 @@ namespace client
|
||||||
if(!ecode)
|
if(!ecode)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_ForwardsMutex);
|
std::lock_guard<std::mutex> lock(m_ForwardsMutex);
|
||||||
for ( auto & s : m_ServerForwards ) s.second->ExpireStale();
|
for (auto & s : m_ServerForwards ) s.second->ExpireStale();
|
||||||
ScheduleCleanupUDP();
|
ScheduleCleanupUDP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,10 +101,7 @@ namespace client
|
||||||
BOBCommandChannel * m_BOBCommandChannel;
|
BOBCommandChannel * m_BOBCommandChannel;
|
||||||
I2CPServer * m_I2CPServer;
|
I2CPServer * m_I2CPServer;
|
||||||
|
|
||||||
boost::asio::io_service m_Service;
|
std::unique_ptr<boost::asio::deadline_timer> m_CleanupUDPTimer;
|
||||||
std::thread * m_ServiceThread;
|
|
||||||
|
|
||||||
boost::asio::deadline_timer m_CleanupUDPTimer;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// for HTTP
|
// for HTTP
|
||||||
|
|
Loading…
Reference in a new issue