Browse Source

wait for close from other side

pull/566/head
orignal 9 years ago
parent
commit
91ec08df4e
  1. 33
      Streaming.cpp

33
Streaming.cpp

@ -66,6 +66,7 @@ namespace stream
m_SendHandler = nullptr; m_SendHandler = nullptr;
handler (boost::asio::error::make_error_code (boost::asio::error::operation_aborted)); handler (boost::asio::error::make_error_code (boost::asio::error::operation_aborted));
} }
m_LocalDestination.DeleteStream (shared_from_this ());
} }
void Stream::HandleNextPacket (Packet * packet) void Stream::HandleNextPacket (Packet * packet)
@ -220,11 +221,18 @@ namespace stream
m_LastReceivedSequenceNumber = receivedSeqn; m_LastReceivedSequenceNumber = receivedSeqn;
if (flags & (PACKET_FLAG_CLOSE | PACKET_FLAG_RESET)) if (flags & PACKET_FLAG_RESET)
{ {
m_Status = eStreamStatusReset; m_Status = eStreamStatusReset;
Close (); Close ();
} }
else if (flags & PACKET_FLAG_CLOSE)
{
if (m_Status != eStreamStatusClosed)
SendClose ();
m_Status = eStreamStatusClosed;
Terminate ();
}
} }
void Stream::ProcessAck (Packet * packet) void Stream::ProcessAck (Packet * packet)
@ -295,7 +303,7 @@ namespace stream
SendBuffer (); SendBuffer ();
} }
if (m_Status == eStreamStatusClosing) if (m_Status == eStreamStatusClosing)
Close (); // all outgoing messages have been sent Close (); // check is all outgoing messages have been sent and we can send close
} }
size_t Stream::Send (const uint8_t * buf, size_t len) size_t Stream::Send (const uint8_t * buf, size_t len)
@ -495,23 +503,19 @@ namespace stream
LogPrint (eLogDebug, "Streaming: Trying to send stream data before closing, sSID=", m_SendStreamID); LogPrint (eLogDebug, "Streaming: Trying to send stream data before closing, sSID=", m_SendStreamID);
break; break;
case eStreamStatusReset: case eStreamStatusReset:
SendClose (); // TODO: send reset
Terminate (); Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ());
break; break;
case eStreamStatusClosing: case eStreamStatusClosing:
if (m_SentPackets.empty () && m_SendBuffer.eof ()) // nothing to send if (m_SentPackets.empty () && m_SendBuffer.eof ()) // nothing to send
{ {
m_Status = eStreamStatusClosed; m_Status = eStreamStatusClosed;
SendClose (); SendClose ();
Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ());
} }
break; break;
case eStreamStatusClosed: case eStreamStatusClosed:
// already closed // already closed
Terminate (); Terminate ();
m_LocalDestination.DeleteStream (shared_from_this ());
break; break;
default: default:
LogPrint (eLogWarning, "Streaming: Unexpected stream status ", (int)m_Status, "sSID=", m_SendStreamID); LogPrint (eLogWarning, "Streaming: Unexpected stream status ", (int)m_Status, "sSID=", m_SendStreamID);
@ -578,15 +582,10 @@ namespace stream
m_AckSendTimer.cancel (); m_AckSendTimer.cancel ();
} }
SendPackets (std::vector<Packet *> { packet }); SendPackets (std::vector<Packet *> { packet });
if (m_Status == eStreamStatusOpen) bool isEmpty = m_SentPackets.empty ();
{ m_SentPackets.insert (packet);
bool isEmpty = m_SentPackets.empty (); if (isEmpty)
m_SentPackets.insert (packet); ScheduleResend ();
if (isEmpty)
ScheduleResend ();
}
else
delete packet;
return true; return true;
} }
else else

Loading…
Cancel
Save