-
Notifications
You must be signed in to change notification settings - Fork 2
/
epoll_server.h
65 lines (44 loc) · 1.36 KB
/
epoll_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
63
64
65
//
// Created by lqx on 2021/3/6.
//
#ifndef EPOLL2_EPOLL_SERVER_H
#define EPOLL2_EPOLL_SERVER_H
#include <map>
#include <sys/epoll.h>
#include "session.h"
using namespace std;
class EpollServer {
private:
//端口
const int port;
map<int, Session *> sessions;
int socketFd{};
const int eventNum;
const int eTimeout;
const int buffLen;
epoll_event *events{};
int eFd = 0;
bool block = true;
public:
EpollServer() : EpollServer(8088, 20, -1, 1024, true) {}
EpollServer(int _port, int _eventNum, int _eTimeout, int _buffLen, bool _block) : port(_port),
eventNum(_eventNum),
eTimeout(_eTimeout),
buffLen(_buffLen) {
this->block = _block;
}
//运行server
bool run();
//新连接加入
void addSession(Session *session);
//删除连接
void delSession(Session *session);
//获一个session
Session *getSession(int sessionId);
//向一个session中写数据
void writeToSession(Session *session, char *data, int size);
virtual ~EpollServer();
private:
bool createSocket();
};
#endif //EPOLL2_EPOLL_SERVER_H