Commit c0e863ee authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Inline receive_packet and rename and add check.

parent 93c0ca07
......@@ -20,19 +20,21 @@
#include "types/packetTimeout.h"
#include "socket.h"
prrtPacketLength_t receive_packet(const PrrtSocket *s, void *buffer, PrrtPacket *packet) {
static inline prrtPacketLength_t deliver_packet(const PrrtSocket *s, void *buffer, PrrtPacket *packet) {
prrtPacketLength_t len = 0;
XlapTimeStampClock(s, ts_data_packet, packet->sequenceNumber, PrrtReceivePackage);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, PrrtReceivePackage);
if(packet != NULL) {
XlapTimeStampClock(s, ts_data_packet, packet->sequenceNumber, PrrtReceivePackage);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, PrrtReceivePackage);
len = (prrtPacketLength_t) (packet->payloadLength - PRRT_PACKET_DATA_HEADER_SIZE);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, CopyOutputStart);
PrrtPacket_copy_payload_to_buffer(buffer, packet, PRRT_PACKET_DATA_HEADER_SIZE);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, CopyOutputEnd);
len = (prrtPacketLength_t) (packet->payloadLength - PRRT_PACKET_DATA_HEADER_SIZE);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, CopyOutputStart);
PrrtPacket_copy_payload_to_buffer(buffer, packet, PRRT_PACKET_DATA_HEADER_SIZE);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, CopyOutputEnd);
XlapTimeStampClock(s, ts_data_packet, packet->sequenceNumber, PrrtDeliver);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, PrrtDeliver);
PrrtPacket_destroy(packet);
XlapTimeStampClock(s, ts_data_packet, packet->sequenceNumber, PrrtDeliver);
XlapTimeStampCycle(s, ts_data_packet, packet->sequenceNumber, PrrtDeliver);
PrrtPacket_destroy(packet);
}
return len;
}
......@@ -272,10 +274,7 @@ int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr) {
PrrtPacket *packet;
packet = PrrtReceiveDataQueue_get_packet(s->receiveDataQueue, 0, MAX_TIMESTAMP);
if(packet != NULL) {
len = receive_packet(s, buf_ptr, packet);
}
return len;
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
......@@ -293,7 +292,7 @@ int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr) {
}
} while (!packet);
return receive_packet(s, buf_ptr, packet);
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
......@@ -301,16 +300,11 @@ int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr) {
}
int32_t PrrtSocket_receive_asap_timedwait(PrrtSocket *s, void *buf_ptr, struct timespec* deadline) {
prrtPacketLength_t len = 0;
check(s->isSender == false, "Cannot receive on sender socket.")
PrrtPacket *packet = PrrtReceiveDataQueue_get_packet_timedwait(s->receiveDataQueue, 0, MAX_TIMESTAMP, deadline);
if(packet != NULL) {
len = receive_packet(s, buf_ptr, packet);
}
return len;
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
return -1;
......@@ -327,11 +321,7 @@ int32_t PrrtSocket_receive_ordered(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t
prrtTimestamp_t now = PrrtClock_get_current_time_us();
PrrtPacket *packet = PrrtReceiveDataQueue_get_packet(s->receiveDataQueue, now - time_window_us, now + time_window_us);
if(packet != NULL) {
len = receive_packet(s, buf_ptr, packet);
}
return len;
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
return -1;
......@@ -351,7 +341,7 @@ int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, prrtTimede
}
} while (!packet);
return receive_packet(s, buf_ptr, packet);
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
......@@ -359,18 +349,12 @@ int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, prrtTimede
}
int32_t PrrtSocket_receive_ordered_timedwait(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us, struct timespec* deadline) {
prrtPacketLength_t len = 0;
check(s->isSender == false, "Cannot receive on sender socket.")
prrtTimestamp_t now = PrrtClock_get_current_time_us();
PrrtPacket *packet = PrrtReceiveDataQueue_get_packet_timedwait(s->receiveDataQueue, now - time_window_us, now + time_window_us, deadline);
if(packet != NULL) {
len = receive_packet(s, buf_ptr, packet);
}
return len;
return deliver_packet(s, buf_ptr, packet);
error:
PERROR("There was a failure while receiving from socket.%s", "");
return -1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment