socket.h 1.53 KB
Newer Older
1
2
3
#ifndef PRRT_SOCKET_H
#define PRRT_SOCKET_H

4
5
6
7
8
#include "../defines.h"
#include "packet.h"
#include "stores/forward_packet_table.h"
#include "../util/list.h"
#include "../util/bptree.h"
9

10
typedef struct prrtReceiver {
11
    const char* host_name;
12
    uint16_t port;
13
} PrrtReceiver;
14

15
typedef struct prrtSocket {
16
17
18
    int dataSocketFd;
    int feedbackSocketFd;
    pthread_t receiveFeedbackThread;
19

20
21
22
23
24
25
26
    pthread_t sendThread;
    pthread_mutex_t outQueueFilledMutex;
    pthread_cond_t outQueueFilledCv;
    List *outQueue;

    pthread_t receiveDataThread;
    pthread_mutex_t inQueueFilledMutex;
27
    pthread_cond_t inQueueFilledCv;
28
    List *inQueue;
29

30
31
32
33
    BPTreeNode* dataStore;

    BPTreeNode* blockStore;

34
35
    PrrtForwardPacketTable* forwardPacketTable;

36
37
    List* receivers;

38
39
40
    pthread_mutex_t closingMutex;
    uint8_t closing;

41
42
43
44
45
    uint16_t packetsCount;
    uint16_t sequenceNumberSource;
    uint16_t sequenceNumberRepetition;
    uint16_t sequenceNumberRedundancy;
    uint16_t sequenceNumberFeedback;
46
    uint8_t is_sender;
47
} PrrtSocket;
48

49

50
PrrtSocket* PrrtSocket_create(const uint16_t port, const uint8_t is_sender);
51
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
52
int PrrtSocket_close(PrrtSocket *sock_ptr);
53
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
54
int PrrtSocket_send(PrrtSocket *sock_ptr, uint8_t *data, const size_t data_len);
55
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
56
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length);
57
58

#endif // PRRT_SOCKET_H