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

4
#include <stdatomic.h>
5
6
#include "../defines.h"
#include "packet.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
7
#include "stores/forwardPacketTable.h"
8
#include "../util/list.h"
Stefan Reif's avatar
Stefan Reif committed
9
#include "../util/pipe.h"
10
#include "../util/bptree.h"
11
#include "channelStateInformation.h"
12
#include "applicationConstraints.h"
13
#include "stores/dataPacketStore.h"
14
15
#include "stores/packetTimeoutTable.h"
#include "stores/repairBlockStore.h"
16
#include "stores/receiveDataQueue.h"
17
#include "clock.h"
18
#include "../xlap/xlap.h"
19

20

21
typedef struct prrtSocket {
22
23
24
    int dataSocketFd;
    int feedbackSocketFd;
    pthread_t receiveFeedbackThread;
25

Andreas Schmidt's avatar
Andreas Schmidt committed
26
    struct sockaddr_in *address;
Andreas Schmidt's avatar
Andreas Schmidt committed
27
28
    bool isBound;

Stefan Reif's avatar
Stefan Reif committed
29
    PrrtClock clock;
30

Andreas Schmidt's avatar
Andreas Schmidt committed
31
    pthread_t sendDataThread;
Andreas Schmidt's avatar
Andreas Schmidt committed
32
    Pipe *sendDataQueue;
33
34

    pthread_t receiveDataThread;
35
36
    PrrtReceiveDataQueue* receiveDataQueue;

37

Andreas Schmidt's avatar
Andreas Schmidt committed
38
39
40
    PrrtPacketTimeoutTable *packetTimeoutTable;
    PrrtDataPacketStore *dataPacketStore;
    PrrtRepairBlockStore *repairBlockStore;
41

Andreas Schmidt's avatar
Andreas Schmidt committed
42
    PrrtForwardPacketTable *forwardPacketTable;
43

Andreas Schmidt's avatar
Andreas Schmidt committed
44
    List *receivers;
45

46
    atomic_bool closing;
47

48
49
50
51
52
53
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
    bool isSender;
54

55
56
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
57

Andreas Schmidt's avatar
Andreas Schmidt committed
58
    PrrtChannelStateInformation *csi;
59
60

    PrrtApplicationConstraints *applicationConstraints;
61
62

    PrrtCodingParams *codingParameters;
63

Andreas Schmidt's avatar
Andreas Schmidt committed
64
    _Atomic (XlapTimestampTable *) tstable[2];
65

Andreas Schmidt's avatar
Andreas Schmidt committed
66
67
68
    pthread_attr_t *receiveFeedbackThreadAttr;
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
69
} PrrtSocket;
70

71

72
PrrtSocket *PrrtSocket_create(const bool is_sender, prrtTimedelta_t target_delay_us);
Andreas Schmidt's avatar
Andreas Schmidt committed
73
74
75
76
77
78
79

bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char *ipAddress, const uint16_t port);

bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char *name, const uint32_t value);

uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const char *name);

80
bool PrrtSocket_set_coding_parameters(PrrtSocket *sock_ptr, uint8_t k, uint8_t n);
Andreas Schmidt's avatar
Andreas Schmidt committed
81

82
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
Andreas Schmidt's avatar
Andreas Schmidt committed
83

84
int PrrtSocket_close(PrrtSocket *sock_ptr);
Andreas Schmidt's avatar
Andreas Schmidt committed
85

86
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
87

88
int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len);
Andreas Schmidt's avatar
Andreas Schmidt committed
89

90
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
Andreas Schmidt's avatar
Andreas Schmidt committed
91

92
93
int32_t PrrtSocket_recv_sync(PrrtSocket *sock_ptr, void *buf_ptr, prrtTimedelta_t time_window_us);

Andreas Schmidt's avatar
Andreas Schmidt committed
94
int32_t PrrtSocket_timedrecv(PrrtSocket *sock_ptr, void *buf_ptr, const uint32_t wait_time);
Andreas Schmidt's avatar
Andreas Schmidt committed
95

96
bool PrrtSocket_cleanup(PrrtSocket *socket);
Andreas Schmidt's avatar
Andreas Schmidt committed
97

Stefan Reif's avatar
Stefan Reif committed
98
bool PrrtSocket_closing(PrrtSocket *socket);
99

100
101
bool PrrtSocket_uses_thread_pinning(PrrtSocket *socket);

102
103
uint32_t PrrtSocket_get_rtt(PrrtSocket *socket);

104
#endif // PRRT_SOCKET_H