socket.h 2.18 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
12
#include "stores/packetTimeoutTable.h"
#include "stores/repairBlockStore.h"
13
#include "clock.h"
14

15

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

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

24
25
    PrrtClock* clock;

26
27
28
29
30
31
32
    pthread_t sendThread;
    pthread_mutex_t outQueueFilledMutex;
    pthread_cond_t outQueueFilledCv;
    List *outQueue;

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

36
37
    pthread_t cleanupThread;

38
39
    BPTreeNode* dataStore;

40
41
42
43
    PrrtPacketTimeoutTable* packetTimeoutTable;

    PrrtDataPacketStore* dataPacketStore;
    PrrtRepairBlockStore* repairBlockStore;
44

45
46
    PrrtForwardPacketTable* forwardPacketTable;

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
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
72
int PrrtSocket_close(PrrtSocket *sock_ptr);
73
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
74
int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len);
75
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
76
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *prrtSocket, const size_t length);
77
78

#endif // PRRT_SOCKET_H