From 29944f6bf29106373e7b701bb7cd7119077f16ca Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 22 Jan 2017 21:22:12 -0500 Subject: [PATCH] cleanup stream upon termination --- Streaming.cpp | 36 +++++++++++++++++++++--------------- Streaming.h | 2 ++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Streaming.cpp b/Streaming.cpp index 343b9b38..86bfcd14 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -36,21 +36,7 @@ namespace stream Stream::~Stream () { - while (!m_ReceiveQueue.empty ()) - { - auto packet = m_ReceiveQueue.front (); - m_ReceiveQueue.pop (); - m_LocalDestination.DeletePacket (packet); - } - - for (auto it: m_SentPackets) - m_LocalDestination.DeletePacket (it); - m_SentPackets.clear (); - - for (auto it: m_SavedPackets) - m_LocalDestination.DeletePacket (it); - m_SavedPackets.clear (); - + CleanUp (); LogPrint (eLogDebug, "Streaming: Stream deleted"); } @@ -65,8 +51,28 @@ namespace stream m_SendHandler = nullptr; handler (boost::asio::error::make_error_code (boost::asio::error::operation_aborted)); } + CleanUp (); m_LocalDestination.DeleteStream (shared_from_this ()); } + + void Stream::CleanUp () + { + m_SendBuffer.str (""); + while (!m_ReceiveQueue.empty ()) + { + auto packet = m_ReceiveQueue.front (); + m_ReceiveQueue.pop (); + m_LocalDestination.DeletePacket (packet); + } + + for (auto it: m_SentPackets) + m_LocalDestination.DeletePacket (it); + m_SentPackets.clear (); + + for (auto it: m_SavedPackets) + m_LocalDestination.DeletePacket (it); + m_SavedPackets.clear (); + } void Stream::HandleNextPacket (Packet * packet) { diff --git a/Streaming.h b/Streaming.h index 828fccc7..bfea74ed 100644 --- a/Streaming.h +++ b/Streaming.h @@ -158,6 +158,8 @@ namespace stream private: + void CleanUp (); + void SendBuffer (); void SendQuickAck (); void SendClose ();