|
|
@ -138,20 +138,8 @@ namespace stream |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_t Stream::Send (uint8_t * buf, size_t len, int timeout) |
|
|
|
size_t Stream::Send (const uint8_t * buf, size_t len, int timeout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_IsOpen) |
|
|
|
|
|
|
|
ConnectAndSend (buf, len); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// TODO: implement
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Stream::ConnectAndSend (uint8_t * buf, size_t len) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_IsOpen = true; |
|
|
|
|
|
|
|
Packet * p = new Packet (); |
|
|
|
Packet * p = new Packet (); |
|
|
|
uint8_t * packet = p->GetBuffer (); |
|
|
|
uint8_t * packet = p->GetBuffer (); |
|
|
|
// TODO: implement setters
|
|
|
|
// TODO: implement setters
|
|
|
@ -167,7 +155,10 @@ namespace stream |
|
|
|
packet[size] = 0; |
|
|
|
packet[size] = 0; |
|
|
|
size++; // NACK count
|
|
|
|
size++; // NACK count
|
|
|
|
size++; // resend delay
|
|
|
|
size++; // resend delay
|
|
|
|
// TODO: for initial packet only, following packets have different falgs
|
|
|
|
if (!m_IsOpen) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// initial packet
|
|
|
|
|
|
|
|
m_IsOpen = true; |
|
|
|
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_SYNCHRONIZE | |
|
|
|
*(uint16_t *)(packet + size) = htobe16 (PACKET_FLAG_SYNCHRONIZE | |
|
|
|
PACKET_FLAG_FROM_INCLUDED | PACKET_FLAG_SIGNATURE_INCLUDED | |
|
|
|
PACKET_FLAG_FROM_INCLUDED | PACKET_FLAG_SIGNATURE_INCLUDED | |
|
|
|
PACKET_FLAG_MAX_PACKET_SIZE_INCLUDED | PACKET_FLAG_NO_ACK); |
|
|
|
PACKET_FLAG_MAX_PACKET_SIZE_INCLUDED | PACKET_FLAG_NO_ACK); |
|
|
@ -184,11 +175,24 @@ namespace stream |
|
|
|
memcpy (packet + size, buf, len); |
|
|
|
memcpy (packet + size, buf, len); |
|
|
|
size += len; // payload
|
|
|
|
size += len; // payload
|
|
|
|
m_LocalDestination->Sign (packet, size, signature); |
|
|
|
m_LocalDestination->Sign (packet, size, signature); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// follow on packet
|
|
|
|
|
|
|
|
*(uint16_t *)(packet + size) = 0; |
|
|
|
|
|
|
|
size += 2; // flags
|
|
|
|
|
|
|
|
*(uint16_t *)(packet + size) = 0; // no options
|
|
|
|
|
|
|
|
size += 2; // options size
|
|
|
|
|
|
|
|
memcpy (packet + size, buf, len); |
|
|
|
|
|
|
|
size += len; // 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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Stream::SendQuickAck () |
|
|
|
void Stream::SendQuickAck () |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t packet[MAX_PACKET_SIZE]; |
|
|
|
uint8_t packet[MAX_PACKET_SIZE]; |
|
|
|