feedback_receiver.c 917 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
    PrrtSocket *sock_ptr = ptr;
12

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

    return NULL;
26
27
28
29

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