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

4
5
#include "../defines.h"
#include "packet.h"
Andreas Schmidt's avatar
Andreas Schmidt committed
6
#include "stores/forwardPacketTable.h"
7
8
#include "../util/list.h"
#include "../util/bptree.h"
9
#include "channelStateInformation.h"
10
#include "applicationConstraints.h"
11
#include "stores/dataPacketStore.h"
12
13
#include "stores/packetTimeoutTable.h"
#include "stores/repairBlockStore.h"
14
#include "clock.h"
15

16

17
typedef struct prrtSocket {
18
19
20
    int dataSocketFd;
    int feedbackSocketFd;
    pthread_t receiveFeedbackThread;
21

Andreas Schmidt's avatar
Andreas Schmidt committed
22
23
24
    struct sockaddr_in* address;
    bool isBound;

25
26
    PrrtClock* clock;

Andreas Schmidt's avatar
Andreas Schmidt committed
27
    pthread_t sendDataThread;
28
29
30
31
32
33
    pthread_mutex_t outQueueFilledMutex;
    pthread_cond_t outQueueFilledCv;
    List *outQueue;

    pthread_t receiveDataThread;
    pthread_mutex_t inQueueFilledMutex;
34
    pthread_cond_t inQueueFilledCv;
35
    List *inQueue;
36

37
38
39
40
41
    pthread_t cleanupThread;

    PrrtPacketTimeoutTable* packetTimeoutTable;
    PrrtDataPacketStore* dataPacketStore;
    PrrtRepairBlockStore* repairBlockStore;
42

43
44
    PrrtForwardPacketTable* forwardPacketTable;

45
46
    PrrtCodingParams* codingParams;

47
48
    List* receivers;

49
    pthread_mutex_t closingMutex;
50
    bool closing;
51

52
53
54
55
56
57
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
    bool isSender;
58

59
60
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
61

62
63
64
    PrrtChannelStateInformation* csi;

    PrrtApplicationConstraints *applicationConstraints;
65
} PrrtSocket;
66

67

68
PrrtSocket *PrrtSocket_create(const bool is_sender);
Andreas Schmidt's avatar
Andreas Schmidt committed
69
bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char* ipAddress, const uint16_t port);
70
bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char* name, const uint32_t value);
71
uint32_t PrrtSocket_get_sock_opt(PrrtSocket *sock_ptr, const char* name);
72
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
73
int PrrtSocket_close(PrrtSocket *sock_ptr);
74
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
75
int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len);
76
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
77
78

#endif // PRRT_SOCKET_H