Browse Source

fix #634.don't create timer in constructor

pull/636/head
orignal 8 years ago
parent
commit
fbb5bb2f05
  1. 43
      ClientContext.cpp
  2. 5
      ClientContext.h

43
ClientContext.cpp

@ -17,8 +17,7 @@ namespace client @@ -17,8 +17,7 @@ namespace client
ClientContext::ClientContext (): m_SharedLocalDestination (nullptr),
m_HttpProxy (nullptr), m_SocksProxy (nullptr), m_SamBridge (nullptr),
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr),
m_CleanupUDPTimer(m_Service, boost::posix_time::seconds(1))
m_BOBCommandChannel (nullptr), m_I2CPServer (nullptr)
{
}
@ -88,20 +87,9 @@ namespace client @@ -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
ReadTunnels ();
// SAM
bool sam; i2p::config::GetOption("sam.enabled", sam);
if (sam) {
@ -149,6 +137,13 @@ namespace client @@ -149,6 +137,13 @@ namespace client
}
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 ()
@ -216,19 +211,16 @@ namespace client @@ -216,19 +211,16 @@ namespace client
m_ClientForwards.clear();
}
if (m_CleanupUDPTimer)
{
m_CleanupUDPTimer->cancel ();
m_CleanupUDPTimer = nullptr;
}
for (auto& it: m_Destinations)
it.second->Stop ();
m_Destinations.clear ();
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 ()
@ -558,9 +550,12 @@ namespace client @@ -558,9 +550,12 @@ namespace client
void ClientContext::ScheduleCleanupUDP()
{
// schedule cleanup in 1 second
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));
if (m_CleanupUDPTimer)
{
// 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)

5
ClientContext.h

@ -101,10 +101,7 @@ namespace client @@ -101,10 +101,7 @@ namespace client
BOBCommandChannel * m_BOBCommandChannel;
I2CPServer * m_I2CPServer;
boost::asio::io_service m_Service;
std::thread * m_ServiceThread;
boost::asio::deadline_timer m_CleanupUDPTimer;
std::unique_ptr<boost::asio::deadline_timer> m_CleanupUDPTimer;
public:
// for HTTP

Loading…
Cancel
Save