delete stream from inside

This commit is contained in:
orignal 2014-12-01 21:26:51 -05:00
parent 38ee813e41
commit 4e54fbec08
7 changed files with 17 additions and 19 deletions

View File

@ -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 ()

View File

@ -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

View File

@ -46,7 +46,6 @@ namespace client
if (m_Stream)
{
m_Stream->Close ();
i2p::stream::DeleteStream (m_Stream);
m_Stream.reset ();
}
m_Socket->close ();

View File

@ -32,7 +32,6 @@ namespace client
if (m_Stream)
{
m_Stream->Close ();
i2p::stream::DeleteStream (m_Stream);
m_Stream.reset ();
}
}

View File

@ -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> stream)
{
if (stream)
stream->GetLocalDestination ().DeleteStream (stream);
}
}
}

View File

@ -190,8 +190,6 @@ namespace stream
const decltype(m_Streams)& GetStreams () const { return m_Streams; };
};
void DeleteStream (std::shared_ptr<Stream> stream);
//-------------------------------------------------
template<typename Buffer, typename ReceiveHandler>

View File

@ -99,10 +99,7 @@ namespace api
void DestroyStream (std::shared_ptr<i2p::stream::Stream> stream)
{
if (stream)
{
stream->Close ();
i2p::stream::DeleteStream (stream);
}
}
}
}