Commit 59b4a78f authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Refactor out duplicate code.

parent 7b95b79c
Pipeline #1551 passed with stages
in 1 minute and 22 seconds
......@@ -181,7 +181,7 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
void receive_from_socket(const PrrtSocket *socket_ptr, unsigned char *buffer_ptr, ssize_t *received_size,
struct sockaddr_in *remote_ptr, socklen_t *remote_len_ptr, struct timespec *packet_stamp_ptr) {
if(socket_ptr->isHardwareTimestamping) {
if (socket_ptr->isHardwareTimestamping) {
struct cmsghdr *cmsg;
struct msghdr msg;
struct iovec entry;
......@@ -203,10 +203,10 @@ void receive_from_socket(const PrrtSocket *socket_ptr, unsigned char *buffer_ptr
*received_size = recvmsg(socket_ptr->dataSocketFd, &msg, 0);
for(cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
switch(cmsg->cmsg_type) {
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
switch (cmsg->cmsg_type) {
case SO_TIMESTAMPNS: {
memcpy(packet_stamp_ptr, (struct timespec*) CMSG_DATA(cmsg), sizeof(struct timespec));
memcpy(packet_stamp_ptr, (struct timespec *) CMSG_DATA(cmsg), sizeof(struct timespec));
break;
}
default:
......@@ -256,26 +256,28 @@ void *receive_data_loop(void *ptr) {
prrtPacketType_t packetType = PrrtPacket_type(packet);
debug(DEBUG_DATARECEIVER, "received packet %d:%u", (int) packetType, seqno);
enum XlapTimestampPacketKind kind = ts_any_packet;
if (packetType == PACKET_TYPE_DATA) {
XlapTimeStampValue(sock_ptr, ts_data_packet, seqno, ChannelReceive, packet_recv_stamp);
XlapTimestampPlaceholderUse(sock_ptr, ts_data_packet, seqno, &tsph1);
XlapTimestampPlaceholderUse(sock_ptr, ts_data_packet, seqno, &tsph2);
XlapTimestampPlaceholderUse(sock_ptr, ts_data_packet, seqno, &tsph3);
XlapTimeStampCycle(sock_ptr, ts_data_packet, seqno, HandlePacketStart);
handle_data_packet(sock_ptr, packet, remote);
XlapTimeStampCycle(sock_ptr, ts_data_packet, seqno, HandlePacketEnd);
kind = ts_data_packet;
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
XlapTimeStampValue(sock_ptr, ts_redundancy_packet, seqno, ChannelReceive, packet_recv_stamp);
XlapTimestampPlaceholderUse(sock_ptr, ts_redundancy_packet, seqno, &tsph1);
XlapTimestampPlaceholderUse(sock_ptr, ts_redundancy_packet, seqno, &tsph2);
XlapTimestampPlaceholderUse(sock_ptr, ts_redundancy_packet, seqno, &tsph3);
XlapTimeStampCycle(sock_ptr, ts_redundancy_packet, seqno, HandlePacketStart);
handle_redundancy_packet(sock_ptr, packet);
XlapTimeStampCycle(sock_ptr, ts_redundancy_packet, seqno, HandlePacketEnd);
kind = ts_redundancy_packet;
}
if (packetType == PACKET_TYPE_DATA || packetType == PACKET_TYPE_REDUNDANCY) {
XlapTimeStampValue(sock_ptr, kind, seqno, ChannelReceive, packet_recv_stamp);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph1);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph2);
XlapTimestampPlaceholderUse(sock_ptr, kind, seqno, &tsph3);
XlapTimeStampCycle(sock_ptr, kind, seqno, HandlePacketStart);
if (packetType == PACKET_TYPE_DATA) {
handle_data_packet(sock_ptr, packet, remote);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
handle_redundancy_packet(sock_ptr, packet);
} else {
goto error;
}
XlapTimeStampCycle(sock_ptr, kind, seqno, HandlePacketEnd);
} else {
PrrtPacket_print(packet);
PrrtPacket_destroy(packet);
......
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