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

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

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

27

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

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

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

Andreas Schmidt's avatar
Andreas Schmidt committed
38
    pthread_t sendDataThread;
Andreas Schmidt's avatar
Andreas Schmidt committed
39
    MPSCQueue *sendDataQueue;
40
41

    pthread_t receiveDataThread;
42
    PrrtPacketDeliveryStore* packetDeliveryStore;
43

44

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

49
    PrrtDeliveredPacketTable *deliveredPacketTable;
50

51
    PrrtReceiver* receiver;
52

53
    atomic_bool closing;
54

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

62
63
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
64

65
    PrrtApplicationConstraints *applicationConstraints;
66
67

    PrrtCodingParams *codingParameters;
68

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

Andreas Schmidt's avatar
Andreas Schmidt committed
71
72
73
    pthread_attr_t *receiveFeedbackThreadAttr;
    pthread_attr_t *sendDataThreadAttr;
    pthread_attr_t *receiveDataThreadAttr;
74

75
    atomic_bool isHardwareTimestamping;
76
    char *interfaceName;
77
78

    atomic_bool isThreadPinning;
79
} PrrtSocket;
80

81

82
83
84
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
85

86
87
bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

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

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

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

94
bool PrrtSocket_set_coding_parameters(PrrtSocket *s, uint8_t k, uint8_t n);
Andreas Schmidt's avatar
Andreas Schmidt committed
95

96
97
PrrtCodingParams *PrrtSocket_get_coding_parameters(PrrtSocket *s);

98
int PrrtSocket_interrupt(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
99

100
int PrrtSocket_close(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
101

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

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

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

108
109
110
111
112
113
114
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);
115

Andreas Schmidt's avatar
Andreas Schmidt committed
116

117
bool PrrtSocket_cleanup(PrrtSocket *s);
Andreas Schmidt's avatar
Andreas Schmidt committed
118

119
bool PrrtSocket_closing(PrrtSocket *s);
120

121
bool PrrtSocket_uses_thread_pinning(PrrtSocket *s);
122

123
uint32_t PrrtSocket_get_rtprop(PrrtSocket *s);
124

125
#endif // PRRT_SOCKET_H