-
Notifications
You must be signed in to change notification settings - Fork 0
/
epollengineer.h
62 lines (53 loc) · 1.49 KB
/
epollengineer.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
#ifndef EPOLLENGINEER_H
#define EPOLLENGINEER_H
#include <sys/socket.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <signal.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/un.h>
#include <set>
#include "supertcpmanager.h"
#include <atomic>
#include <functional>
#include <map>
class SuperTcpManager;
class Epoll
{
// using exceptions from SuperTcpManager
public:
Epoll();
void addServer();
void removeServer();
void addFileDescriptor(int fd, std::function<void(epoll_event)> callFunc);
void removeFileDescriptor(int fd);
void setFdOpt(int fd, unsigned int opt);
void writeMsg(int fd, const std::string& msg);
void execute();
~Epoll();
//signals:
// void newMessageEpoll(int socketFd, std::string message);
// void newConnection(int portFd, int socketFd);
// void closedConnection(int socketFd);
static const int DEFAULT_EVENTS = EPOLLIN;
static std::atomic_bool sigHandle;
static std::atomic_bool epollRunning;
private:
Epoll(const Epoll& ep) = delete;
Epoll(Epoll&& ep) = delete;
Epoll& operator=(Epoll& ep) = delete;
void closeSocket(int sfd);
std::atomic_int countServers;
epoll_event event;
int epollFileDescriptor;
int epollTimeout;
std::thread serverThread;
std::map<int, std::function<void(epoll_event)> > fdFunc;
static const int MAXEVENTS = 64;
static const int MAXDATASIZE = 512;
};
#endif // EPOLLENGINEER_H