-
Notifications
You must be signed in to change notification settings - Fork 0
/
UDPNetwork.h
78 lines (65 loc) · 2.35 KB
/
UDPNetwork.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*************************************************************************
> File Name: UDPNetwork.h
> Author: test
> Mail: [email protected]
> Created Time: Sun 30 Nov 2014 07:20:16 AM PST
************************************************************************/
#ifndef UDPNETWORK_H
#define UDPNETWORK_H
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <arpa/inet.h>
//#include <openssl/ssl.h>
//#include <openssl/err.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <pthread.h>
#include <assert.h>
#include <bitset>
#include <cmath>
#include "pdfs.h"
#include "thirdparty/include/udt.h"
namespace pdfs {
class UDPNetwork {
public:
int setnonblocking(int sockfd);
// Return a sockaddr_in with specified ip and port
struct sockaddr_in getSockAddr(unsigned long ip = INADDR_ANY,
unsigned short port = 2300);
struct sockaddr_in getSockAddr(std::string ip = "127.0.0.1",
unsigned short port = 2300);
// Retrun a regular socket
int getRawSocket();
int getUDTRawSocket();
// Get a socket binded a sockaddr_in
int getListener(unsigned short port = 2300,
unsigned long ip = INADDR_ANY);
int getUDTListener(unsigned short port = 2300,
unsigned long ip = INADDR_ANY);
// Get epoll fd
int getEpollfd(int udp_sfd);
int getUDTEpollfd(int udp_sfd);
int getConnection(std::string destIP = "127.0.0.1",
unsigned short port = 2300);
int getUDTConnection(std::string destIP = "127.0.0.1",
unsigned short port = 2300);
// Send a message with message header only
int sendMessage(struct messageheader header, std::string destIP,
unsigned short destPort);
// send Ack message
int replyAck(struct sockaddr_in &addr, char *replyMsg);
// Function of thread to receive ack message
static void *recvAckThread(void *sack);
}; // end class UDPNetwork
} // end namespace pdfs
#endif