-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
85 lines (66 loc) · 2.75 KB
/
Copy pathserver.h
File metadata and controls
85 lines (66 loc) · 2.75 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
79
80
81
82
83
84
85
#ifndef SERVER_H
#define SERVER_H
#include<string>
#include<memory>
#include<array>
#include<sys/epoll.h>
#include "./thread_pool/thread_pool.h"
#include "./http/http_connection.h"
#include "./mysql_connection_pool/mysql_connection_pool.h"
#include "./timer/timer.h"
#include "./server_log/server_log.h"
const int kMaxFd = 65536; //最大文件描述符
const int kMaxEventNumber=10000; //最大事件数
const int kTimeSlot = 5; //最小超时单位
class Server
{
public:
Server();
~Server();
void Init(int port , std::string user, std::string password, std::string database_name,
int log_write , int opt_linger, int trig_mode, int sql_num,
int thread_num, int close_log, int actor_model);
void ThreadPoolInit();
void SqlPool();
void LogInit();
void TrigMode();
void EventListen();
void EventLoop();
void TimerInit(int connfd, struct sockaddr_in client_address);
void AdjustTimer(std::shared_ptr<Timer> timer);
void DealTimer(std::shared_ptr<Timer> timer, int sock_fd); //关闭客户的连接,移除相应计时器
bool DealClientData();
bool DealWithSignal(bool& timeout, bool& stop_server); //DealWithSignal将根据pip_fd_[0]中读取的信号决定,是否将time_out,stop_server置为1,从而控制服务器的行动。
void DealWithRead(int sock_fd);
void DealWithWrite(int sock_fd);
public:
//基础
int port_; //服务器监听的端口号
std::string file_root_dir_; //服务器文件的根目录
int log_write_;
int close_log_;
int actor_model_;
int pipe_fd_[2]; //往pipe_fd_[1]中写入系统信号,从pipe_fd_[0]中读取系统信号
int epoll_fd_;
std::shared_ptr< std::shared_ptr<HttpConnection>[] > user_http_connections_; //HttpConnection类对象的数组
//数据库相关
std::shared_ptr<MysqlConnectionPool> sql_pool_; //mysql数据库连接池
std::string database_user_; //登陆数据库用户名
std::string database_password_; //登陆数据库密码
std::string database_name_; //使用数据库名
int sql_num_;
//线程池相关
std::shared_ptr< ThreadPool<HttpConnection> > thread_pool_;
int thread_num_;
//epoll_event相关
epoll_event events_[kMaxEventNumber];
int listen_fd_;
int opt_linger_; //opt_linger=0为优雅关闭连接,opt_linger=1时会延时关闭
int trig_mode_; //用于设置listen_trig_mode_和connect_trig_mode_
int listen_trig_mode_; //控制监听文件描述符的相关事件的触发模式
int connect_trig_mode_;
//定时器相关
std::shared_ptr< std::shared_ptr<ClientData>[] > user_timers_; //user_timers_指向一个 保存有客户数据的共享指针 的数组
Utils utils_;
};
#endif