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

Andreas Schmidt's avatar
Andreas Schmidt committed
4
5
6
7
#include <src/defines.h>
#include <src/util/list.h>
#include <src/prrt/packet.h>
#include <src/prrt/stores/forward_packet_table.h>
8
#include <src/util/bptree.h>
9
10

typedef struct {
11
    const char* host_name;
12
    uint16_t port;
13
} PrrtReceiver;
14
15

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

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

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

30
31
32
33
    BPTreeNode* dataStore;

    BPTreeNode* blockStore;

34
35
    PrrtForwardPacketTable* forwardPacketTable;

36
37
    List* receivers;

38
39
40
    pthread_mutex_t closingMutex;
    uint8_t closing;

41
42
43
44
45
    uint16_t packetsCount;
    uint16_t sequenceNumberSource;
    uint16_t sequenceNumberRepetition;
    uint16_t sequenceNumberRedundancy;
    uint16_t sequenceNumberFeedback;
46
} PrrtSocket;
47

48

49
bool PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender);
50
int PrrtSocket_interrupt(PrrtSocket *sock_ptr);
51
int PrrtSocket_close(PrrtSocket *sock_ptr);
52
53
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len);
54
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr);
55
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length);
56
57

#endif // PRRT_SOCKET_H