socket.h 1.84 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 "applicationContraints.h"
11

12

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

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

21
22
23
24
25
26
27
    pthread_t sendThread;
    pthread_mutex_t outQueueFilledMutex;
    pthread_cond_t outQueueFilledCv;
    List *outQueue;

    pthread_t receiveDataThread;
    pthread_mutex_t inQueueFilledMutex;
28
    pthread_cond_t inQueueFilledCv;
29
    List *inQueue;
30

31
32
33
34
    BPTreeNode* dataStore;

    BPTreeNode* blockStore;

35
36
    PrrtForwardPacketTable* forwardPacketTable;

37
38
    List* receivers;

39
    pthread_mutex_t closingMutex;
40
    bool closing;
41

42
43
44
45
46
47
    prrtSequenceNumber_t packetsCount;
    prrtSequenceNumber_t sequenceNumberSource;
    prrtSequenceNumber_t sequenceNumberRepetition;
    prrtSequenceNumber_t sequenceNumberRedundancy;
    prrtSequenceNumber_t sequenceNumberFeedback;
    bool isSender;
48

49
50
    prrtTimestamp_t lastSentTimestamp;
    prrtTimestamp_t lastReceivedTimestamp;
51

52
53
54
    PrrtChannelStateInformation* csi;

    PrrtApplicationConstraints *applicationConstraints;
55
} PrrtSocket;
56

57

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

#endif // PRRT_SOCKET_H