Http/HttpServer 服务端操作类 更多...
#include <sttnet.h>
Public 成员函数 | |
| void | putTask (const std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> &fun, HttpServerFDHandler &k, HttpRequestInformation &inf) |
| 把一个任务放入工作线程池由工作线程完成 更多... | |
| HttpServer (const unsigned long long &maxFD=1000000, const int &buffer_size=256, const bool &security_open=true, const int &connectionNumLimit=10, const int &connectionSecs=1, const int &connectionTimes=3, const int &requestSecs=1, const int &requestTimes=20, const int &checkFrequency=30, const int &connectionTimeout=30) | |
| 构造函数,默认是允许最大1000000个连接,每个连接接收缓冲区最大为256kb,启用安全模块。 更多... | |
| void | setSecuritySendBackFun (std::function< void(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| 设置违反信息安全策略时候的返回函数 更多... | |
| void | setGlobalSolveFunction (std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| 设置全局备用函数 更多... | |
| void | setFunction (const std::string &key, std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| 设置key对应的收到客户端消息后的回调函数 更多... | |
| void | setGetKeyFunction (std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> parseKeyFun) |
| 设置解析出key的回调函数 更多... | |
| bool | startListen (const int &port, const int &threads=8) |
| 打开Http服务器监听程序 更多... | |
| ~HttpServer () | |
| 析构函数 更多... | |
Public 成员函数 继承自 stt::network::TcpServer | |
| void | putTask (const std::function< int(TcpFDHandler &k, TcpInformation &inf)> &fun, TcpFDHandler &k, TcpInformation &inf) |
| 把一个任务放入工作线程池由工作线程完成 更多... | |
| TcpServer (const unsigned long long &maxFD=1000000, const int &buffer_size=256, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionSecs=1, const int &connectionTimes=6, const int &requestSecs=1, const int &requestTimes=40, const int &checkFrequency=60, const int &connectionTimeout=60) | |
| 构造函数,默认是允许最大1000000个连接,每个连接接收缓冲区最大为256kb,启用安全模块。 更多... | |
| 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证书等 更多... | |
| void | setSecuritySendBackFun (std::function< void(TcpFDHandler &k, TcpInformation &inf)> fc) |
| 设置违反信息安全策略时候的返回函数 更多... | |
| void | setGlobalSolveFunction (std::function< bool(TcpFDHandler &k, TcpInformation &inf)> fc) |
| 设置全局备用函数 更多... | |
| void | setFunction (const std::string &key, std::function< int(TcpFDHandler &k, TcpInformation &inf)> fc) |
| 设置key对应的收到客户端消息后的回调函数 更多... | |
| void | setGetKeyFunction (std::function< int(TcpFDHandler &k, TcpInformation &inf)> parseKeyFun) |
| 设置解析出key的回调函数 更多... | |
| bool | stopListen () |
| 停止监听 更多... | |
| bool | close () |
| 关闭监听和所有已连接的套接字 更多... | |
| virtual bool | close (const int &fd) |
| 关闭某个套接字的连接 更多... | |
| void | setConnectStrategy (const stt::security::RateLimitType &type) |
| 设置“连接速率限流”所使用的策略。 更多... | |
| void | setRequestStrategy (const stt::security::RateLimitType &type) |
| 设置“IP 级请求限流”所使用的策略。 更多... | |
| void | setPathStrategy (const stt::security::RateLimitType &type) |
| 设置“path 级请求限流”所使用的策略。 更多... | |
| void | setPathLimit (const std::string &path, const int ×, const int &secs) |
| 设置某个路径的额外限流规则(path 级)。 更多... | |
| void | setCloseFun (std::function< void(const int &fd)> closeFun) |
| 设置关闭tcp连接之后调用的函数 更多... | |
| bool | isListen () |
| 返回对象的监听状态 更多... | |
| SSL * | getSSL (const int &fd) |
| 查询和服务端的连接,传入套接字,返回加密的SSL句柄 更多... | |
| ~TcpServer () | |
| TcpServer 类的析构函数 更多... | |
额外继承的成员函数 | |
Protected 属性 继承自 stt::network::TcpServer | |
| std::queue< WorkerMessage > | finishQueue |
| stt::system::WorkerPool * | workpool |
| unsigned long | buffer_size |
| unsigned long long | maxFD |
| security::ConnectionLimiter | connectionLimiter |
| TcpFDInf * | clientfd |
| int | flag1 =true |
| bool | unblock |
| SSL_CTX * | ctx =nullptr |
| bool | TLS =false |
| bool | security_open |
| int | workerEventFD |
| int | serverType |
| int | connectionSecs |
| int | connectionTimes |
| int | requestSecs |
| int | requestTimes |
| int | checkFrequency |
Http/HttpServer 服务端操作类
|
inline |
构造函数,默认是允许最大1000000个连接,每个连接接收缓冲区最大为256kb,启用安全模块。
| maxFD | 服务对象的最大接受连接数 默认为1000000 |
| buffer_size | 同一个连接允许传输的最大数据量(单位为kb) 默认为256kb |
| security_open | true:开启安全模块 false:关闭安全模块 (默认为开启) |
| connectionNumLimit | 同一个ip连接数目的上限(默认10) |
| connectionSecs | 连接速率统计窗口长度(单位:秒)(默认1秒) |
| connectionTimes | 在 connectionSecs 秒内允许的最大连接次数 (默认3次) |
| requestSecs | 请求速率统计窗口长度(单位:秒)(默认1秒) |
| requestTimes | 在秒requestSecs内允许的最大请求数量(默认20次) |
| checkFrequency | 检查僵尸连接的频率(单位:秒) -1为不做检查 (默认为30秒) |
| connectionTimeout | 连接多少秒内没有任何反应就视为僵尸连接 (单位为秒) -1为无限制 (默认30秒) |
|
inline |
析构函数
| void stt::network::HttpServer::putTask | ( | const std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> & | fun, |
| HttpServerFDHandler & | k, | ||
| HttpRequestInformation & | inf | ||
| ) |
把一个任务放入工作线程池由工作线程完成
| fun | 放入工作线程池的可执行对象 -参数:HttpServerFDHandler &k - 和客户端连接的套接字的操作对象的引用 HttpRequestInformation &inf - 客户端信息,保存数据,处理进度,状态机信息等 -返回值:-2:处理失败并且需要关闭连接 -1:处理失败但不需要关闭连接 1:处理成功 |
| k | 和客户端连接的套接字的操作对象的引用 |
| inf | 客户端信息的引用,保存数据,处理进度,状态机信息等 |
|
inline |
设置key对应的收到客户端消息后的回调函数
| key | 找到对应回调函数的key |
| fc | 一个函数或函数对象,用于收到客户端消息后处理逻辑 -参数:HttpServerFDHandler &k - 和客户端连接的套接字的操作对象的引用 HttpRequestInformation &inf - 客户端信息,保存数据,处理进度,状态机信息等 -返回值:-2:处理失败并且需要关闭连接 -1:处理失败但不需要关闭连接 0:处理流程已经扔入工作线程池,需要等待处理完成 1:处理成功 httpserver->setFunction("/ping",[](HttpServerFDHandler &k,HttpRequestInformation &inf)->int
{
k.sendBack("pong");
return 1;
});
httpserver->setFunction("/ping",[](HttpServerFDHandler &k,HttpRequestInformation &inf)->int
{
httpserver->putTask([](HttpServerFDHandler &k,HttpRequestInformation &inf)->int
{
k.sendBack("pong");
return 1;
},k,inf);
return 0;
});
|
|
inline |
设置解析出key的回调函数
| parseKeyFun | 解析key的回调函数 -参数:HttpServerFDHandler &k - 和客户端连接的套接字的操作对象的引用 HttpRequestInformation &inf - 客户端信息,保存数据,处理进度,状态机信息等 -返回值:-2:处理失败并且需要关闭连接 -1:处理失败但不需要关闭连接 0:处理流程已经扔入工作线程池,需要等待处理完成 1:处理成功 httpserver->setGetKeyFunction([](HttpServerFDHandler &k,HttpRequestInformation &inf)->int
{
inf.ctx["key"]=inf.loc;
return 1;
});
|
|
inline |
设置全局备用函数
| fc | 一个函数或函数对象,用于收到客户端消息后处理逻辑 -参数:HttpServerFDHandler &k - 和客户端连接的套接字的操作对象的引用 HttpRequestInformation &inf - 客户端信息,保存数据,处理进度,状态机信息等
|
|
inline |
设置违反信息安全策略时候的返回函数
| key | 找到对应回调函数的key |
| fc | 一个函数或函数对象,用于收到客户端消息后处理逻辑 -参数:HttpServerFDHandler &k - 和客户端连接的套接字的操作对象的引用 HttpRequestInformation &inf - 客户端信息,保存数据,处理进度,状态机信息等 -返回值:true:处理成功 false:处理失败 会关闭连接 |
|
inline |
打开Http服务器监听程序
| port | 监听的端口 |
| threads | 消费者线程的数量 (默认为8) |
1.8.5