From a85cc6aa773ed2246165517bee7bb30eb548450f Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 11 Jan 2015 21:00:38 -0500 Subject: [PATCH] fixed race condition --- NTCPSession.cpp | 9 +++++++-- NTCPSession.h | 1 + SSU.h | 3 ++- SSUSession.cpp | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 753d1950..870d67df 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -627,6 +627,11 @@ namespace transport } void NTCPSession::SendI2NPMessage (I2NPMessage * msg) + { + m_Server.GetService ().post (std::bind (&NTCPSession::PostI2NPMessage, shared_from_this (), msg)); + } + + void NTCPSession::PostI2NPMessage (I2NPMessage * msg) { if (msg) { @@ -634,9 +639,9 @@ namespace transport Send (msg); else m_DelayedMessages.push_back (msg); - } + } } - + void NTCPSession::ScheduleTermination () { m_TerminationTimer.cancel (); diff --git a/NTCPSession.h b/NTCPSession.h index b08f6e44..6938f0ae 100644 --- a/NTCPSession.h +++ b/NTCPSession.h @@ -67,6 +67,7 @@ namespace transport protected: + void PostI2NPMessage (I2NPMessage * msg); void Connected (); void SendTimeSyncMessage (); void SetIsEstablished (bool isEstablished) { m_IsEstablished = isEstablished; } diff --git a/SSU.h b/SSU.h index 1e3624a4..057a42a2 100644 --- a/SSU.h +++ b/SSU.h @@ -38,7 +38,8 @@ namespace transport void DeleteSession (std::shared_ptr session); void DeleteAllSessions (); - boost::asio::io_service& GetService () { return m_Socket.get_io_service(); }; + boost::asio::io_service& GetService () { return m_Service; }; + boost::asio::io_service& GetServiceV6 () { return m_ServiceV6; }; const boost::asio::ip::udp::endpoint& GetEndpoint () const { return m_Endpoint; }; void Send (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& to); void AddRelay (uint32_t tag, const boost::asio::ip::udp::endpoint& relay); diff --git a/SSUSession.cpp b/SSUSession.cpp index 41a24470..11044921 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -828,7 +828,8 @@ namespace transport void SSUSession::SendI2NPMessage (I2NPMessage * msg) { - m_Server.GetService ().post (std::bind (&SSUSession::PostI2NPMessage, shared_from_this (), msg)); + boost::asio::io_service& service = IsV6 () ? m_Server.GetServiceV6 () : m_Server.GetService (); + service.post (std::bind (&SSUSession::PostI2NPMessage, shared_from_this (), msg)); } void SSUSession::PostI2NPMessage (I2NPMessage * msg)