Browse Source

handle stream close depending on state

pull/163/head
orignal 10 years ago
parent
commit
cd0933522d
  1. 40
      Streaming.cpp
  2. 2
      Streaming.h

40
Streaming.cpp

@ -34,6 +34,12 @@ namespace stream
} }
Stream::~Stream () Stream::~Stream ()
{
Terminate ();
LogPrint (eLogDebug, "Stream deleted");
}
void Stream::Terminate ()
{ {
m_AckSendTimer.cancel (); m_AckSendTimer.cancel ();
while (!m_ReceiveQueue.empty ()) while (!m_ReceiveQueue.empty ())
@ -52,7 +58,6 @@ namespace stream
for (auto it: m_SavedPackets) for (auto it: m_SavedPackets)
delete it; delete it;
m_SavedPackets.clear (); m_SavedPackets.clear ();
LogPrint (eLogDebug, "Stream deleted");
} }
void Stream::HandleNextPacket (Packet * packet) void Stream::HandleNextPacket (Packet * packet)
@ -438,23 +443,34 @@ namespace stream
void Stream::Close () void Stream::Close ()
{ {
if (m_Status == eStreamStatusOpen) switch (m_Status)
{ {
case eStreamStatusOpen:
m_Status = eStreamStatusClosing; m_Status = eStreamStatusClosing;
if (m_SendBuffer.eof ()) // nothing to send Close (); // recursion
SendClose (); if (m_Status == eStreamStatusClosing) //still closing
} LogPrint (eLogInfo, "Trying to send stream data before closing");
if (m_Status == eStreamStatusReset || m_SentPackets.empty ()) break;
case eStreamStatusReset:
Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ());
break;
case eStreamStatusClosing:
if (m_SentPackets.empty () && m_SendBuffer.eof ()) // nothing to send
{ {
// closed by peer or everything has been acknowledged
if (m_Status == eStreamStatusClosing)
SendClose (); SendClose ();
m_ReceiveTimer.cancel (); Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ()); m_LocalDestination.DeleteStream (shared_from_this ());
} }
else break;
LogPrint (eLogInfo, "Trying to send stream data before closing"); case eStreamStatusClosed:
// already closed
Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ());
break;
default:
LogPrint (eLogWarning, "Unexpected stream status ", (int)m_Status);
};
} }
void Stream::SendClose () void Stream::SendClose ()

2
Streaming.h

@ -131,6 +131,8 @@ namespace stream
private: private:
void Terminate ();
void SendBuffer (); void SendBuffer ();
void SendQuickAck (); void SendQuickAck ();
void SendClose (); void SendClose ();

Loading…
Cancel
Save