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

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

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

29

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

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

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

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

    pthread_t receiveDataThread;
44
    PrrtPacketDeliveryStore* packetDeliveryStore;
45

46

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

51
    PrrtDeliveredPacketTable *deliveredPacketTable;
52

53
    PrrtReceiver* receiver;
54

55
    atomic_bool closing;
56

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

64
65
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
66

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

    PrrtReceptionTable* dataReceptionTable;
    PrrtReceptionTable* redundancyReceptionTable;

72
    PrrtApplicationConstraints *applicationConstraints;
73
74

    PrrtCodingParams *codingParameters;
75

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

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

82
    atomic_bool isHardwareTimestamping;
83
    char *interfaceName;
84
85

    atomic_bool isThreadPinning;
86
} PrrtSocket;
87

88

89
90
91
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
92

93
94
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

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

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

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

rna's avatar
rna committed
101
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
102

103
104
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);

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

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

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

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

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

115
116
117
118
119
120
121
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);
122

Andreas Schmidt's avatar
Andreas Schmidt committed
123

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

126
bool PrrtSocket_closing(PrrtSocket *s);
127

128
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
129

130
uint32_t PrrtSocket_get_rtprop(PrrtSocket *s);
131

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

136
#endif // PRRT_SOCKET_H