-
Notifications
You must be signed in to change notification settings - Fork 6
/
ncsocket.h
33 lines (30 loc) · 1.19 KB
/
ncsocket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef _NCSOCKET_H_
#define _NCSOCKET_H_
#include <atomic>
#include <thread>
#include "networkcodingheader.h"
#include "nctx.h"
#include "ncrx.h"
class ncsocket{
public:
ncsocket(unsigned short int port, unsigned int tx_timeout_milli, unsigned int rx_timeout_milli, std::function <void (unsigned char* buffer, unsigned int length, sockaddr_in addr)> rx);
~ncsocket();
private:
enum STATE : unsigned char{
INIT_FAILURE,
INIT_SUCCESS
};
STATE _state;
int _socket;
nctx* _nc_tx;
ncrx* _nc_rx;
std::atomic<bool> _is_rx_thread_running;
std::thread _rx_thread;
unsigned char _rx_buffer[ETHERNET_MTU];
public:
bool open_session(unsigned int ip, unsigned short int port, BLOCK_SIZE block_size, unsigned int retransmssion_interval, unsigned char redundancy = 0xff);
bool connect_session(unsigned int client_ip, unsigned short int cport, unsigned char probes, unsigned int timeout);
void close_session(unsigned int ip, unsigned short int port);
int send(unsigned int ip, unsigned short int port, unsigned char* buff, unsigned int size, bool force_start_retransmission, unsigned int ack_timeout = 1000, tx_session_param* new_param = nullptr);
};
#endif