-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.h
85 lines (64 loc) · 1.64 KB
/
Socket.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
79
80
81
82
83
84
85
#ifndef Socket_h__
#define Socket_h__
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <cassert>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <map>
#include <memory>
struct ErrorMSG {
static const std::string kSyntaxError ;
static const std::string kArgError ;
static const std::string kPortError ;
};
/* template<typename T, typename... Args> */
// std::unique_ptr<T> make_unique(Args&&... args) {
// return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
/* } */
class Socket {
private:
int sd;
struct sockaddr_in sin;
Socket();
protected:
void set_sd(int _sd) {
sd = _sd;
}
public:
int get_sd() const {
return sd;
}
struct sockaddr_in get_sin() const {
return sin;
}
void close();
/**
* @Brief Create a passive socket listener; TCP
*
* @Param ip IP to attach to, INADDR_ANY if NULL
* @Param port port to listen on
* @Param num_connections max # of tcp connections allowed to wait
*
*/
Socket(const char* ip, int port);
Socket(int sd, struct sockaddr_in sin):sd(sd), sin(sin){}
/**
* @Brief Disable copy constructor and assignment
*
* @Param Socket
*/
Socket(const Socket&) = delete;
Socket& operator=(const Socket&) = delete;
virtual ~Socket();
void connect();
void bind();
};
#endif