-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.h
62 lines (55 loc) · 1.04 KB
/
server.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
//
// server.h
//
// Created by 吴怡生 on 1/03/2018.
// Copyright © 2018 yeshen.org. All rights reserved.
//
#ifndef SERVER_H
#define SERVER_H
#include <map>
#include <sys/epoll.h>
using namespace std;
class Section
{
private:
int status; //SectionStatus
char * host;
char * port;
char cmd;
public:
int inner;
int outter;
Section(int inner_fd);
bool ready();
bool handshake();
char connet();
bool forward(int from);
void destory();
};
class SectionPool
{
public:
map<int,Section*> data;
SectionPool();
void put(Section* section);
void update(int fd,Section* section);
void remove(Section* section);
void remove(int fd);
map<int, Section*>::iterator find(int fd);
};
class Server
{
private:
SectionPool pool;
struct epoll_event* event;
int epoll_fd;
int watch_port(int port);
bool add_into_epoll(int sock_fd);
bool accept_connect(int sock_fd);
bool close_connect(int fd);
void handle(int from);
public:
Server();
void forever();
};
#endif