Browse Source

split stream to packets

pull/93/head
orignal 10 years ago
parent
commit
297afeb07b
  1. 17
      Streaming.cpp

17
Streaming.cpp

@ -202,6 +202,8 @@ namespace stream
size_t Stream::Send (const uint8_t * buf, size_t len, int timeout) size_t Stream::Send (const uint8_t * buf, size_t len, int timeout)
{ {
bool isNoAck = m_LastReceivedSequenceNumber < 0; // first packet bool isNoAck = m_LastReceivedSequenceNumber < 0; // first packet
while (len > 0)
{
Packet * p = new Packet (); Packet * p = new Packet ();
uint8_t * packet = p->GetBuffer (); uint8_t * packet = p->GetBuffer ();
// TODO: implement setters // TODO: implement setters
@ -238,8 +240,11 @@ namespace stream
uint8_t * signature = packet + size; // set it later uint8_t * signature = packet + size; // set it later
memset (signature, 0, 40); // zeroes for now memset (signature, 0, 40); // zeroes for now
size += 40; // signature size += 40; // signature
memcpy (packet + size, buf, len); size_t sentLen = STREAMING_MTU - size;
size += len; // payload if (len < sentLen) sentLen = len;
memcpy (packet + size, buf, sentLen);
len -= sentLen;
size += sentLen; // payload
m_LocalDestination->Sign (packet, size, signature); m_LocalDestination->Sign (packet, size, signature);
} }
else else
@ -249,11 +254,15 @@ namespace stream
size += 2; // flags size += 2; // flags
*(uint16_t *)(packet + size) = 0; // no options *(uint16_t *)(packet + size) = 0; // no options
size += 2; // options size size += 2; // options size
memcpy (packet + size, buf, len); size_t sentLen = STREAMING_MTU - size;
size += len; // payload if (len < sentLen) sentLen = len;
memcpy (packet + size, buf, sentLen);
len -= sentLen;
size += sentLen; // payload
} }
p->len = size; p->len = size;
m_Service.post (boost::bind (&Stream::SendPacket, this, p)); m_Service.post (boost::bind (&Stream::SendPacket, this, p));
}
return len; return len;
} }

Loading…
Cancel
Save