Skip to content

Commit

Permalink
teminate hadlers upon cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Aug 11, 2017
1 parent 8cb612c commit 309822d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 8 additions & 0 deletions libi2pd_client/I2PService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ namespace client
if (m_LocalDestination) m_LocalDestination->Release ();
}

void I2PService::ClearHandlers ()
{
std::unique_lock<std::mutex> l(m_HandlersMutex);
for (auto it: m_Handlers)
it->Terminate ();
m_Handlers.clear();
}

void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, int port) {
assert(streamRequestComplete);
i2p::data::IdentHash identHash;
Expand Down
9 changes: 4 additions & 5 deletions libi2pd_client/I2PService.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ namespace client
std::unique_lock<std::mutex> l(m_HandlersMutex);
m_Handlers.erase(conn);
}
inline void ClearHandlers ()
{
std::unique_lock<std::mutex> l(m_HandlersMutex);
m_Handlers.clear();
}
void ClearHandlers ();

inline std::shared_ptr<ClientDestination> GetLocalDestination () { return m_LocalDestination; }
inline std::shared_ptr<const ClientDestination> GetLocalDestination () const { return m_LocalDestination; }
Expand Down Expand Up @@ -66,6 +62,9 @@ namespace client
virtual ~I2PServiceHandler() { }
//If you override this make sure you call it from the children
virtual void Handle() {}; //Start handling the socket

void Terminate () { Kill (); };

protected:
// Call when terminating or handing over to avoid race conditions
inline bool Kill () { return m_Dead.exchange(true); }
Expand Down

0 comments on commit 309822d

Please sign in to comment.