-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpServer.h
More file actions
78 lines (53 loc) · 1.38 KB
/
Copy pathHttpServer.h
File metadata and controls
78 lines (53 loc) · 1.38 KB
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
69
70
71
72
73
74
75
76
77
78
#ifndef HTTPSERVER_HTTPSERVER_H
#define HTTPSERVER_HTTPSERVER_H
#include "ThreadPool.h"
#include "Timer.h"
#include "HttpConn.h"
#include "ConnectionPool.h"
#include <string>
#include <unordered_map>
/*
采用半同步半反应堆并发模式
*/
class HttpServer {
public:
HttpServer(int port,
int threadNum,
std::string userName, std::string passWd,
std::string databaseName, int sqlNum);
~HttpServer();
void loop();
private:
void threadPoolInit_();
void eventLoopInit_();
void databaseInit_();
void dealWithRead_(HttpConn* conn);
void dealWithWrite_(HttpConn* conn);
void dealWithListen_();
void dealWithError_(HttpConn* conn, uint32_t events);
void closeConn_(HttpConn* conn);
void extentTime(HttpConn* conn);
// socket相关
int port_;
int listenFd_;
static const int kMaxFd = 65536;
// eventloop相关
int epollFd_;
static const int kMaxEventNum = 4096;
struct epoll_event* activeFds_;
// 定时相关
TimerHeap timerHeap_;
// 线程池相关
ThreadPool<HttpConn> threadPool_;
// 数据库相关
ConnectionPool* connPool_;
std::string userName_;
std::string passWd_;
std::string databaseName_;
int sqlNum_;
// http连接相关
HttpConn* userConns_;
// 根路径
char* docRoot_;
};
#endif