STTNet
 全部  命名空间 文件 函数 变量 类型定义 宏定义 
Public 成员函数 | 所有成员列表
stt::network::HttpServer类 参考

Http/HttpServer 服务端操作类 更多...

#include <sttnet.h>

类 stt::network::HttpServer 继承关系图:
stt::network::TcpServer

Public 成员函数

 HttpServer (const int &maxFD=10000000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=60)
 构造函数,默认是启用安全模块。限制一个ip最大连接为20;同一个ip每秒最快连接速度为6 更多...
 
bool setFunction (std::function< bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc)
 设置一个收到Http/Https请求并成功解析后进行响应的回调函数 注册一个回调函数 更多...
 
- Public 成员函数 继承自 stt::network::TcpServer
 TcpServer (const int &maxFD=10000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=1800)
 构造函数,默认是启用安全模块。限制一个ip最大连接为20;同一个ip每秒最快连接速度为6 更多...
 
bool startListen (const int &port, const int &threads=8)
 打开Tcp服务器监听程序 更多...
 
bool setTLS (const char *cert, const char *key, const char *passwd, const char *ca)
 启用 TLS 加密并配置服务器端证书与密钥 更多...
 
void redrawTLS ()
 撤销TLS加密,ca证书等 更多...
 
bool setFunction (std::function< bool(TcpFDHandler &k, TcpFDInf &inf)> fc)
 设置收到客户端消息后的回调函数 注册一个回调函数 更多...
 
bool stopListen ()
 停止监听 更多...
 
bool close ()
 关闭监听和所有已连接的套接字 更多...
 
bool close (const int &fd)
 关闭某个套接字的连接 更多...
 
bool isListen ()
 返回对象的监听状态 更多...
 
SSL * getSSL (const int &fd)
 查询和服务端的连接,传入套接字,返回加密的SSL句柄 更多...
 
 ~TcpServer ()
 TcpServer 类的析构函数 更多...
 

额外继承的成员函数

- Protected 成员函数 继承自 stt::network::TcpServer
bool allowRequest (const int &cclientfd)
 
void connectionDetect ()
 
- Protected 属性 继承自 stt::network::TcpServer
unsigned long buffer_size
 
int maxFD
 
security::ConnectionLimiter connectionLimiter
 
TcpFDInfclientfd
 
int flag1 =true
 
std::queue< QueueFD > * fdQueue
 
std::mutex * lq1
 
std::condition_variable * cv
 
int consumerNum
 
std::mutex lco1
 
bool unblock
 
SSL_CTX * ctx =nullptr
 
bool TLS =false
 
int requestRate
 
int checkFrequency
 
int connectionTimeout
 
bool security_open
 

详细描述

Http/HttpServer 服务端操作类

注解
支持http/1.0 1.1

构造及析构函数说明

stt::network::HttpServer::HttpServer ( const int &  maxFD = 10000000,
const bool &  security_open = true,
const int &  connectionNumLimit = 20,
const int &  connectionRateLimit = 6,
const int &  buffer_size = 8,
const int &  requestRate = 12,
const int &  checkFrequency = 1,
const int &  connectionTimeout = 60 
)
inline

构造函数,默认是启用安全模块。限制一个ip最大连接为20;同一个ip每秒最快连接速度为6

注解
打开安全模块会对性能有影响
参数
maxFD服务对象的最大接受连接数
security_opentrue:开启安全模块 false:关闭安全模块 (默认为开启)
connectionNumLimit同一个ip连接数目的上限
connectionRateLimit同一个ip每秒钟连接数目的上限
buffer_size同一个连接允许传输的最大数据量(单位为kb) 默认为8kb
requestRatte同一个连接一秒内允许的最大请求数量 (默认为12次)
checkFrequency检查僵尸连接的频率(单位分钟) 默认为1分钟 -1为不做检查
connectionTimeout连接多少秒内没有任何反应就视为僵尸连接 (单位为秒) 默认60秒 -1为无限制

成员函数说明

bool stt::network::HttpServer::setFunction ( std::function< bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)>  fc)
inline

设置一个收到Http/Https请求并成功解析后进行响应的回调函数 注册一个回调函数

参数
fc一个函数或函数对象,用于当收到Http/Https请求并成功解析后进行响应的回调函数 -参数:HttpRequestInformation &inf - Http/Https请求的信息 HttpServerFDHandler &k - 服务端对象的引用 -返回: bool - 返回true成功成功,返回false处理失败
注解
传入的函数应该有如下签名 bool func(const HttpRequestInformation &inf,HttpServerFDHandler &k)
如果处理失败了 会关闭连接

该类的文档由以下文件生成: