diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 7a2e181e..4be5517b 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -85,8 +85,17 @@ namespace client else { if (m_Stream) - m_Stream->Send (m_Buffer, bytes_transferred); - Receive (); + { + auto s = shared_from_this (); + m_Stream->AsyncSend (m_Buffer, bytes_transferred, + [s](const boost::system::error_code& ecode) + { + if (!ecode) + s->Receive (); + else + s->Terminate (); + }); + } } } diff --git a/SAM.cpp b/SAM.cpp index c241641e..971ed45e 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -558,8 +558,17 @@ namespace client else { if (m_Stream) - m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred); - Receive (); + { + auto s = shared_from_this (); + m_Stream->AsyncSend ((uint8_t *)m_Buffer, bytes_transferred, + [s](const boost::system::error_code& ecode) + { + if (!ecode) + s->Receive (); + else + s->Terminate (); + }); + } } }