mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-11 19:10:55 +00:00
handle stream close depending on state
This commit is contained in:
parent
dc599bbc63
commit
cd0933522d
@ -34,6 +34,12 @@ namespace stream
|
||||
}
|
||||
|
||||
Stream::~Stream ()
|
||||
{
|
||||
Terminate ();
|
||||
LogPrint (eLogDebug, "Stream deleted");
|
||||
}
|
||||
|
||||
void Stream::Terminate ()
|
||||
{
|
||||
m_AckSendTimer.cancel ();
|
||||
while (!m_ReceiveQueue.empty ())
|
||||
@ -52,7 +58,6 @@ namespace stream
|
||||
for (auto it: m_SavedPackets)
|
||||
delete it;
|
||||
m_SavedPackets.clear ();
|
||||
LogPrint (eLogDebug, "Stream deleted");
|
||||
}
|
||||
|
||||
void Stream::HandleNextPacket (Packet * packet)
|
||||
@ -438,23 +443,34 @@ namespace stream
|
||||
|
||||
void Stream::Close ()
|
||||
{
|
||||
if (m_Status == eStreamStatusOpen)
|
||||
switch (m_Status)
|
||||
{
|
||||
case eStreamStatusOpen:
|
||||
m_Status = eStreamStatusClosing;
|
||||
if (m_SendBuffer.eof ()) // nothing to send
|
||||
SendClose ();
|
||||
}
|
||||
if (m_Status == eStreamStatusReset || m_SentPackets.empty ())
|
||||
Close (); // recursion
|
||||
if (m_Status == eStreamStatusClosing) //still closing
|
||||
LogPrint (eLogInfo, "Trying to send stream data before closing");
|
||||
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 ();
|
||||
m_ReceiveTimer.cancel ();
|
||||
Terminate ();
|
||||
m_LocalDestination.DeleteStream (shared_from_this ());
|
||||
}
|
||||
else
|
||||
LogPrint (eLogInfo, "Trying to send stream data before closing");
|
||||
|
||||
break;
|
||||
case eStreamStatusClosed:
|
||||
// already closed
|
||||
Terminate ();
|
||||
m_LocalDestination.DeleteStream (shared_from_this ());
|
||||
break;
|
||||
default:
|
||||
LogPrint (eLogWarning, "Unexpected stream status ", (int)m_Status);
|
||||
};
|
||||
}
|
||||
|
||||
void Stream::SendClose ()
|
||||
|
@ -131,6 +131,8 @@ namespace stream
|
||||
|
||||
private:
|
||||
|
||||
void Terminate ();
|
||||
|
||||
void SendBuffer ();
|
||||
void SendQuickAck ();
|
||||
void SendClose ();
|
||||
|
Loading…
Reference in New Issue
Block a user