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

Loading…
Cancel
Save