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

4
5
#include "../defines.h"
#include "../util/list.h"
Stefan Reif's avatar
Stefan Reif committed
6
#include "../util/pipe.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
7
#include "../util/mpsc_queue.h"
8
#include "../util/bptree.h"
9
#include "channelStateInformation.h"
10
#include "applicationConstraints.h"
11
#include "stores/dataPacketStore.h"
12
#include "stores/deliveredPacketTable.h"
13
#include "stores/packetTimeoutTable.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
14
#include "stores/receptionTable.h"
15
#include "stores/repairBlockStore.h"
16
#include "stores/packetDeliveryStore.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
17
#include "types/lossStatistics.h"
18
#include "types/packet.h"
19
#include "clock.h"
20
#include "../xlap/xlap.h"
21
#include "receiver.h"
22

23
24
25
26
27
#ifndef SIOCSHWTSTAMP
# define SIOCSHWTSTAMP  0x89b0
# define SIOCGHWTSTAMP  0x89b1
#endif

28

29
typedef struct prrtSocket {
30
31
32
    int dataSocketFd;
    int feedbackSocketFd;
    pthread_t receiveFeedbackThread;
33

Andreas Schmidt's avatar
Andreas Schmidt committed
34
    struct sockaddr_in *address;
Andreas Schmidt's avatar
Andreas Schmidt committed
35
36
    bool isBound;

Stefan Reif's avatar
Stefan Reif committed
37
    PrrtClock clock;
38

Andreas Schmidt's avatar
Andreas Schmidt committed
39
    pthread_t sendDataThread;
40
    Pipe *sendDataQueue;
41
42

    pthread_t receiveDataThread;
43
    PrrtPacketDeliveryStore* packetDeliveryStore;
44

45

Andreas Schmidt's avatar
Andreas Schmidt committed
46
47
48
    PrrtPacketTimeoutTable *packetTimeoutTable;
    PrrtDataPacketStore *dataPacketStore;
    PrrtRepairBlockStore *repairBlockStore;
49

50
    PrrtDeliveredPacketTable *deliveredPacketTable;
51

52
    PrrtReceiver* receiver;
53

54
    atomic_bool closing;
55

56
57
58
59
60
61
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
    bool isSender;
62

63
64
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
65

Andreas Schmidt's avatar
Andreas Schmidt committed
66
67
68
69
70
    PrrtLossStatistics lossStatistics;

    PrrtReceptionTable* dataReceptionTable;
    PrrtReceptionTable* redundancyReceptionTable;

71
    PrrtApplicationConstraints *applicationConstraints;
72
73

    PrrtCodingParams *codingParameters;
74

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

Andreas Schmidt's avatar
Andreas Schmidt committed
77
78
79
    pthread_attr_t *receiveFeedbackThreadAttr;
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
80

81
    atomic_bool isHardwareTimestamping;
82
    char *interfaceName;
83
84

    atomic_bool isThreadPinning;
85
} PrrtSocket;
86

87

88
89
90
PrrtSocket *PrrtSocket_create(bool is_sender, prrtTimedelta_t target_delay_us);

bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interface_name);
Andreas Schmidt's avatar
Andreas Schmidt committed
91

92
93
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

94
bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
95

96
bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t value);
Andreas Schmidt's avatar
Andreas Schmidt committed
97

98
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *s, const char *name);
Andreas Schmidt's avatar
Andreas Schmidt committed
99

rna's avatar
rna committed
100
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle);
Andreas Schmidt's avatar
Andreas Schmidt committed
101

102
103
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);

104
int PrrtSocket_interrupt(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
105

106
int PrrtSocket_close(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
107

108
int PrrtSocket_connect(PrrtSocket *s, const char *host, uint16_t port);
Andreas Schmidt's avatar
Andreas Schmidt committed
109

110
int PrrtSocket_send(PrrtSocket *s, const uint8_t *data, size_t data_len);
Andreas Schmidt's avatar
Andreas Schmidt committed
111

112
int32_t PrrtSocket_recv(PrrtSocket *s, void *buf_ptr);
Andreas Schmidt's avatar
Andreas Schmidt committed
113

114
115
116
117
118
119
120
int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr);
int32_t PrrtSocket_receive_asap_wait(PrrtSocket *s, void *buf_ptr);
int32_t PrrtSocket_receive_asap_timedwait(PrrtSocket *s, void *buf_ptr, struct timespec* deadline);

int32_t PrrtSocket_receive_ordered(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us);
int32_t PrrtSocket_receive_ordered_wait(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us);
int32_t PrrtSocket_receive_ordered_timedwait(PrrtSocket *s, void *buf_ptr, prrtTimedelta_t time_window_us, struct timespec* deadline);
121

Andreas Schmidt's avatar
Andreas Schmidt committed
122

123
bool PrrtSocket_cleanup(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
124

125
bool PrrtSocket_closing(PrrtSocket *s);
126

127
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
128

129
uint32_t PrrtSocket_get_rtprop(PrrtSocket *s);
130

131
132
prrtPacketLossRate_t PrrtSocket_get_plr(PrrtSocket *s);
prrtDeliveryRate_t PrrtSocket_get_delivery_rate(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
133
prrtDeliveryRate_t PrrtSocket_get_btlbw(PrrtSocket *s);
134
bool PrrtSocket_get_app_limited(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
135

136
#endif // PRRT_SOCKET_H