Fix received packet storing unnecessary header
Added rtt (uint16_t) to UDPC_PacketInfo.
This commit is contained in:
parent
fdd57bc538
commit
1a39039065
4 changed files with 34 additions and 4 deletions
|
@ -263,6 +263,8 @@ uint32_t generateConnectionID(Context &ctx);
|
|||
|
||||
float durationToFSec(const std::chrono::steady_clock::duration& duration);
|
||||
|
||||
uint16_t durationToMS(const std::chrono::steady_clock::duration& duration);
|
||||
|
||||
float timePointsToFSec(
|
||||
const std::chrono::steady_clock::time_point& older,
|
||||
const std::chrono::steady_clock::time_point& newer);
|
||||
|
|
|
@ -1657,11 +1657,12 @@ void UDPC::Context::update_impl() {
|
|||
"Received packet is out of order");
|
||||
}
|
||||
|
||||
if((pktType == 0 && bytes > (int)UDPC_NSFULL_HEADER_SIZE)
|
||||
| (pktType == 1 && bytes > (int)UDPC_LSFULL_HEADER_SIZE)) {
|
||||
if(pktType == 0 && bytes > (int)UDPC_NSFULL_HEADER_SIZE) {
|
||||
UDPC_PacketInfo recPktInfo = UDPC::get_empty_pinfo();
|
||||
std::memcpy(recPktInfo.data, recvBuf, bytes);
|
||||
recPktInfo.dataSize = bytes;
|
||||
std::memcpy(recPktInfo.data + UDPC_NSFULL_HEADER_SIZE,
|
||||
recvBuf,
|
||||
bytes - UDPC_NSFULL_HEADER_SIZE);
|
||||
recPktInfo.dataSize = bytes - UDPC_NSFULL_HEADER_SIZE;
|
||||
recPktInfo.flags =
|
||||
(isConnect ? 0x1 : 0)
|
||||
| (isPing ? 0x2 : 0)
|
||||
|
@ -1671,6 +1672,25 @@ void UDPC::Context::update_impl() {
|
|||
recPktInfo.receiver.addr = in6addr_loopback;
|
||||
recPktInfo.sender.port = ntohs(receivedData.sin6_port);
|
||||
recPktInfo.receiver.port = ntohs(socketInfo.sin6_port);
|
||||
recPktInfo.rtt = durationToMS(iter->second.rtt);
|
||||
|
||||
receivedPkts.push(recPktInfo);
|
||||
} else if(pktType == 1 && bytes > (int)UDPC_LSFULL_HEADER_SIZE) {
|
||||
UDPC_PacketInfo recPktInfo = UDPC::get_empty_pinfo();
|
||||
std::memcpy(recPktInfo.data + UDPC_LSFULL_HEADER_SIZE,
|
||||
recvBuf,
|
||||
bytes - UDPC_LSFULL_HEADER_SIZE);
|
||||
recPktInfo.dataSize = bytes - UDPC_LSFULL_HEADER_SIZE;
|
||||
recPktInfo.flags =
|
||||
(isConnect ? 0x1 : 0)
|
||||
| (isPing ? 0x2 : 0)
|
||||
| (isNotRecChecked ? 0x4 : 0)
|
||||
| (isResending ? 0x8 : 0);
|
||||
recPktInfo.sender.addr = receivedData.sin6_addr;
|
||||
recPktInfo.receiver.addr = in6addr_loopback;
|
||||
recPktInfo.sender.port = ntohs(receivedData.sin6_port);
|
||||
recPktInfo.receiver.port = ntohs(socketInfo.sin6_port);
|
||||
recPktInfo.rtt = durationToMS(iter->second.rtt);
|
||||
|
||||
receivedPkts.push(recPktInfo);
|
||||
} else {
|
||||
|
@ -1753,6 +1773,10 @@ float UDPC::durationToFSec(const std::chrono::steady_clock::duration& duration)
|
|||
/ (float)std::decay_t<decltype(duration)>::period::den;
|
||||
}
|
||||
|
||||
uint16_t UDPC::durationToMS(const std::chrono::steady_clock::duration& duration) {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
|
||||
}
|
||||
|
||||
float UDPC::timePointsToFSec(
|
||||
const std::chrono::steady_clock::time_point& older,
|
||||
const std::chrono::steady_clock::time_point& newer) {
|
||||
|
@ -1766,6 +1790,7 @@ UDPC_PacketInfo UDPC::get_empty_pinfo() {
|
|||
{0}, // data (array)
|
||||
0, // flags
|
||||
0, // dataSize
|
||||
0, // rtt
|
||||
{ // sender
|
||||
{0}, // ipv6 addr
|
||||
0, // scope_id
|
||||
|
|
|
@ -168,6 +168,7 @@ typedef struct {
|
|||
* was received.
|
||||
*/
|
||||
uint16_t dataSize;
|
||||
uint16_t rtt;
|
||||
/// The \p UDPC_ConnectionId of the sender
|
||||
UDPC_ConnectionId sender;
|
||||
/// The \p UDPC_ConnectionId of the receiver
|
||||
|
|
|
@ -271,11 +271,13 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
do {
|
||||
received = UDPC_get_received(context, &size);
|
||||
// printf("Received data size = %u\n", received.dataSize);
|
||||
if(received.dataSize == sizeof(unsigned int)) {
|
||||
if((received.flags & 0x8) != 0) {
|
||||
temp2 = ntohl(*((unsigned int*)received.data));
|
||||
printf("Got out of order, data = %u\n", temp2);
|
||||
}
|
||||
// printf("Got rtt %u\n", received.rtt);
|
||||
}
|
||||
} while (size > 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue