-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.h
68 lines (55 loc) · 1.32 KB
/
webserver.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
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/epoll.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <string>
#include <cassert>
#include <time.h>
#include "threadpool/threadpool.h"
#include "http/http_conn.h"
#include "timer/lst_timer.h"
#define MAX_FD 65535
#define MAX_EVENT_NUMBER 10000
#define TIMESLOT 5
class WebServer
{
public:
WebServer();
~WebServer();
void thread_pool();
void init(int port, string user, string passwd, string dbname, int sql_num);
void sql_pool();
void eventListen();
void eventLoop();
public:
//数据库相关
connection_pool* m_connpool;
string m_user;
string m_passwd;
string m_dbname;
int m_sql_num;
private:
//基本信息
int m_port;
http_conn* users;
//线程池相关
threadpool<http_conn>* m_pool;
//监听与时间循环
struct epoll_event events[MAX_EVENT_NUMBER];
int m_listenfd;
int m_epollfd;
//定时器相关
Utils utils;
int m_pipefd[2];
client_data* users_timer;
private:
void set_timer(int connfd, struct sockaddr_in client_address);
void deal_timer(util_timer* timer, int sockfd);
void update_timer(util_timer* timer);
bool dealwithsignal(bool &timeout, bool &stop_server);
};