diff --git a/Destination.cpp b/Destination.cpp index 98f617eb..e5c0fc78 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -66,8 +66,18 @@ namespace client void ClientDestination::Run () { - if (m_Service) - m_Service->run (); + while (m_IsRunning) + { + try + { + if (m_Service) + m_Service->run (); + } + catch (std::exception& ex) + { + LogPrint ("Destination: ", ex.what ()); + } + } } void ClientDestination::Start () diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 522c87c8..7fb92115 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -516,12 +516,10 @@ namespace util { if (!m_Stream) return; m_Socket->close (); - if (m_Stream->IsOpen ()) - m_Stream->Close (); + m_Stream->Close (); m_Socket->get_io_service ().post ([=](void) { - i2p::stream::DeleteStream (m_Stream); m_Stream.reset (); m_Stream = nullptr; // delete this diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 0dd58698..e24ad7c6 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -46,7 +46,6 @@ namespace client if (m_Stream) { m_Stream->Close (); - i2p::stream::DeleteStream (m_Stream); m_Stream.reset (); } m_Socket->close (); diff --git a/SAM.cpp b/SAM.cpp index 3135f106..b94f9e0d 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -32,7 +32,6 @@ namespace client if (m_Stream) { m_Stream->Close (); - i2p::stream::DeleteStream (m_Stream); m_Stream.reset (); } } diff --git a/Streaming.cpp b/Streaming.cpp index 7a19123c..9cc48dfc 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -207,6 +207,7 @@ namespace stream m_IsOpen = false; m_IsReset = true; m_ReceiveTimer.cancel (); + m_LocalDestination.DeleteStream (shared_from_this ()); } } @@ -549,9 +550,11 @@ namespace stream packets.push_back (it); else { - Close (); + LogPrint (eLogWarning, "Packet ", it->GetSeqn (), "was not ACKed after ", MAX_NUM_RESEND_ATTEMPTS, " attempts. Terminate"); + m_IsOpen = false; m_IsReset = true; m_ReceiveTimer.cancel (); + m_LocalDestination.DeleteStream (shared_from_this ()); return; } } @@ -715,11 +718,5 @@ namespace stream delete uncompressed; } } - - void DeleteStream (std::shared_ptr stream) - { - if (stream) - stream->GetLocalDestination ().DeleteStream (stream); - } } } diff --git a/Streaming.h b/Streaming.h index db4102e1..ff34df9a 100644 --- a/Streaming.h +++ b/Streaming.h @@ -190,8 +190,6 @@ namespace stream const decltype(m_Streams)& GetStreams () const { return m_Streams; }; }; - void DeleteStream (std::shared_ptr stream); - //------------------------------------------------- template diff --git a/api/api.cpp b/api/api.cpp index c172227e..daf82722 100644 --- a/api/api.cpp +++ b/api/api.cpp @@ -99,10 +99,7 @@ namespace api void DestroyStream (std::shared_ptr stream) { if (stream) - { stream->Close (); - i2p::stream::DeleteStream (stream); - } } } }