Browse Source

send close after buffer

pull/163/head
orignal 9 years ago
parent
commit
36de881041
  1. 28
      Streaming.cpp
  2. 1
      Streaming.h

28
Streaming.cpp

@ -359,6 +359,8 @@ namespace stream @@ -359,6 +359,8 @@ namespace stream
m_SentPackets.insert (it);
}
SendPackets (packets);
if (!m_IsOpen && m_SendBuffer.eof ())
SendClose ();
if (isEmpty)
ScheduleResend ();
}
@ -438,6 +440,22 @@ namespace stream @@ -438,6 +440,22 @@ namespace stream
if (m_IsOpen)
{
m_IsOpen = false;
if (m_SendBuffer.eof ()) // nothing to send
SendClose ();
}
if (m_IsReset || m_SentPackets.empty ())
{
// closed by peer or everything has been acknowledged
m_ReceiveTimer.cancel ();
m_LocalDestination.DeleteStream (shared_from_this ());
}
else
LogPrint (eLogInfo, "Trying to send stream data before closing");
}
void Stream::SendClose ()
{
Packet * p = new Packet ();
uint8_t * packet = p->GetBuffer ();
size_t size = 0;
@ -466,16 +484,6 @@ namespace stream @@ -466,16 +484,6 @@ namespace stream
m_Service.post (std::bind (&Stream::SendPacket, shared_from_this (), p));
LogPrint ("FIN sent");
}
if (m_IsReset || (m_SentPackets.empty () && m_SendBuffer.eof ()))
{
// no more outgoing data or closed by peer
m_ReceiveTimer.cancel ();
m_LocalDestination.DeleteStream (shared_from_this ());
}
else
LogPrint (eLogInfo, "Trying to send stream data before closing");
}
size_t Stream::ConcatenatePackets (uint8_t * buf, size_t len)
{

1
Streaming.h

@ -124,6 +124,7 @@ namespace stream @@ -124,6 +124,7 @@ namespace stream
void SendBuffer ();
void SendQuickAck ();
void SendClose ();
bool SendPacket (Packet * packet);
void SendPackets (const std::vector<Packet *>& packets);

Loading…
Cancel
Save