-
Notifications
You must be signed in to change notification settings - Fork 3
/
TCPServer.hpp
46 lines (36 loc) · 869 Bytes
/
TCPServer.hpp
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
//
// TCPServer.hpp
// TYDB
//
// Created by TYPCN on 2016/9/18.
//
//
#ifndef TCPServer_hpp
#define TCPServer_hpp
#include <stdio.h>
#include <unistd.h>
#include <vector>
using namespace std;
class TCPServer {
private:
ev::io io;
ev::sig sio;
int fd;
int af;
socklen_t addrlen;
public:
TCPServer();
void io_accept(ev::io &watcher, int revents);
void on_data(int fd, const uint8_t *buf, uint32_t len, const struct sockaddr* addr, socklen_t addrlen);
void on_event(int fd, int code, const char* msg, const struct sockaddr* addr, socklen_t addrlen);
static void signal_cb(ev::sig &signal, int revents) {
signal.loop.break_loop();
}
virtual ~TCPServer() {
io.stop();
sio.stop();
::shutdown(fd, SHUT_RDWR);
::close(fd);
}
};
#endif /* TCPServer_hpp */