Browse Source

send packets of a longer message at the that time

pull/113/head
orignal 10 years ago
parent
commit
eb6b04d6c2
  1. 32
      Streaming.cpp
  2. 1
      Streaming.h

32
Streaming.cpp

@ -246,6 +246,7 @@ namespace stream @@ -246,6 +246,7 @@ namespace stream
size_t Stream::Send (const uint8_t * buf, size_t len)
{
bool isNoAck = m_LastReceivedSequenceNumber < 0; // first packet
std::vector<Packet *> packets;
while (!m_IsOpen || len > 0)
{
Packet * p = new Packet ();
@ -309,9 +310,10 @@ namespace stream @@ -309,9 +310,10 @@ namespace stream
size += sentLen; // payload
}
p->len = size;
m_Service.post (std::bind (&Stream::SendPacket, this, p));
packets.push_back (p);
}
if (packets.size () > 0)
m_Service.post (std::bind (&Stream::PostPackets, this, packets));
return len;
}
@ -420,7 +422,31 @@ namespace stream @@ -420,7 +422,31 @@ namespace stream
else
return false;
}
void Stream::PostPackets (const std::vector<Packet *> packets)
{
if (m_IsOpen)
{
if (packets.size () > 0)
{
m_IsAckSendScheduled = false;
m_AckSendTimer.cancel ();
}
bool isEmpty = m_SentPackets.empty ();
for (auto it: packets)
m_SentPackets.insert (it);
SendPackets (packets);
if (isEmpty)
ScheduleResend ();
}
else
{
// delete
for (auto it: packets)
delete it;
}
}
void Stream::SendPackets (const std::vector<Packet *>& packets)
{
if (!m_RemoteLeaseSet)

1
Streaming.h

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

Loading…
Cancel
Save