mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 16:34:13 +00:00
handle stream close depending on state
This commit is contained in:
parent
dc599bbc63
commit
cd0933522d
@ -35,6 +35,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)
|
||||||
{
|
{
|
||||||
m_Status = eStreamStatusClosing;
|
case eStreamStatusOpen:
|
||||||
if (m_SendBuffer.eof ()) // nothing to send
|
m_Status = eStreamStatusClosing;
|
||||||
SendClose ();
|
Close (); // recursion
|
||||||
}
|
if (m_Status == eStreamStatusClosing) //still closing
|
||||||
if (m_Status == eStreamStatusReset || m_SentPackets.empty ())
|
LogPrint (eLogInfo, "Trying to send stream data before closing");
|
||||||
{
|
break;
|
||||||
// closed by peer or everything has been acknowledged
|
case eStreamStatusReset:
|
||||||
if (m_Status == eStreamStatusClosing)
|
Terminate ();
|
||||||
SendClose ();
|
m_LocalDestination.DeleteStream (shared_from_this ());
|
||||||
m_ReceiveTimer.cancel ();
|
break;
|
||||||
m_LocalDestination.DeleteStream (shared_from_this ());
|
case eStreamStatusClosing:
|
||||||
}
|
if (m_SentPackets.empty () && m_SendBuffer.eof ()) // nothing to send
|
||||||
else
|
{
|
||||||
LogPrint (eLogInfo, "Trying to send stream data before closing");
|
SendClose ();
|
||||||
|
Terminate ();
|
||||||
|
m_LocalDestination.DeleteStream (shared_from_this ());
|
||||||
|
}
|
||||||
|
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 ()
|
void Stream::SendClose ()
|
||||||
|
@ -131,6 +131,8 @@ namespace stream
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void Terminate ();
|
||||||
|
|
||||||
void SendBuffer ();
|
void SendBuffer ();
|
||||||
void SendQuickAck ();
|
void SendQuickAck ();
|
||||||
void SendClose ();
|
void SendClose ();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user