feedback_receiver.c 1007 Bytes
Newer Older
1
2
#include <string.h>
#include <unistd.h>
3
#include "../../defines.h"
4
5
#include "../../util/common.h"
#include "../../util/dbg.h"
6
7
#include "../packet.h"
#include "../socket.h"
8
9
#include "feedback_receiver.h"

10
void * receive_feedback_loop(void *ptr) {
11
12
    char bufin[MAX_PAYLOAD_LENGTH];

13
    PrrtSocket *sock_ptr = ptr;
14

15
    check(pthread_mutex_lock(&sock_ptr->closingMutex) == 0, "Lock failed.");
16
    while (sock_ptr->closing == false) {
17
        check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
18
        memset(bufin, 0, MAX_PAYLOAD_LENGTH);
19
        PrrtPacket *t = PrrtSocket_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
20
        if (t != NULL) {
21
            PrrtPacket_destroy(t);
22
        }
23
        usleep(1);
24
        check(pthread_mutex_lock(&sock_ptr->closingMutex) == 0, "Lock failed.");
25
    }
26
    check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
27
28

    return NULL;
29
30
31
32

    error:
        PERROR("Feedback reception failed.");
        return NULL;
33
}