|
| 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 size_t &finishQueue_cap=65536, 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 类的析构函数 更多...
|
| |
| stt::network::TcpServer::TcpServer |
( |
const unsigned long long & |
maxFD = 1000000, |
|
|
const int & |
buffer_size = 256, |
|
|
const size_t & |
finishQueue_cap = 65536, |
|
|
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 |
|
) |
| |
|
inline |
构造函数,默认是允许最大1000000个连接,每个连接接收缓冲区最大为256kb,启用安全模块。
@note 打开安全模块会对性能有影响
@param maxFD 服务对象的最大接受连接数 默认为1000000
@param buffer_size 同一个连接允许传输的最大数据量(单位为kb) 默认为256kb
@param finishQueue_cap Worker 完成队列(Worker → Reactor)的容量,必须为 2 的幂。
该队列用于承载 worker 线程已完成任务的结果,等待 reactor 线程消费。 这是主数据通路的一部分,对系统吞吐和延迟极其敏感。
选型原则: finishQueue_cap >= 峰值完成速率(QPS) × reactor 最坏暂停时间
建议值(经验):
- 低负载/轻业务: 8192 (~8k)
- 常规高并发: 65536 (~64k) 【默认】
- 极端突发流量: 131072(~128k)
队列满时 请求将会丢弃,框架不会阻塞生产者。
- 参数
-
| security_open | true:开启安全模块 false:关闭安全模块 (默认为开启) |
| connectionNumLimit | 同一个ip连接数目的上限(默认20) |
| connectionSecs | 连接速率统计窗口长度(单位:秒)(默认1秒) |
| connectionTimes | 在 connectionSecs 秒内允许的最大连接次数 (默认6次) |
| requestSecs | 请求速率统计窗口长度(单位:秒)(默认1秒) |
| requestTimes | 在秒requestSecs内允许的最大请求数量(默认40次) |
| checkFrequency | 检查僵尸连接的频率(单位秒钟) -1为不做检查 (默认为60秒) |
| connectionTimeout | 连接多少秒内没有任何反应就视为僵尸连接 (单位为秒) -1为无限制 (默认60秒) |