socket.h 1.97 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 "clock.h"
12

13

14
typedef struct prrtSocket {
15
16
17
    int dataSocketFd;
    int feedbackSocketFd;
    pthread_t receiveFeedbackThread;
18

Andreas Schmidt's avatar
Andreas Schmidt committed
19
20
21
    struct sockaddr_in* address;
    bool isBound;

22
23
    PrrtClock* clock;

24
25
26
27
28
29
30
    pthread_t sendThread;
    pthread_mutex_t outQueueFilledMutex;
    pthread_cond_t outQueueFilledCv;
    List *outQueue;

    pthread_t receiveDataThread;
    pthread_mutex_t inQueueFilledMutex;
31
    pthread_cond_t inQueueFilledCv;
32
    List *inQueue;
33

34
35
36
37
    BPTreeNode* dataStore;

    BPTreeNode* blockStore;

38
39
    PrrtForwardPacketTable* forwardPacketTable;

40
41
    List* receivers;

42
    pthread_mutex_t closingMutex;
43
    bool closing;
44

45
46
47
48
49
50
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
    bool isSender;
51

52
53
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
54

55
56
57
    PrrtChannelStateInformation* csi;

    PrrtApplicationConstraints *applicationConstraints;
58
} PrrtSocket;
59

60

61
PrrtSocket *PrrtSocket_create(const bool is_sender);
Andreas Schmidt's avatar
Andreas Schmidt committed
62
bool PrrtSocket_bind(PrrtSocket *sock_ptr, const char* ipAddress, const uint16_t port);
63
bool PrrtSocket_set_sock_opt(PrrtSocket *sock_ptr, const char* name, const uint32_t value);
64
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
65
int PrrtSocket_close(PrrtSocket *sock_ptr);
66
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
67
int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len);
68
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
69
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *prrtSocket, const size_t length);
70
71

#endif // PRRT_SOCKET_H