|
| void | putTask (const std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> &fun, HttpServerFDHandler &k, HttpRequestInformation &inf) |
| | Submit a task to the worker thread pool. More...
|
| |
| | HttpServer (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=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) |
| | Constructor. More...
|
| |
| void | setSecuritySendBackFun (std::function< void(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| | Set the callback invoked when an information security policy is violated. More...
|
| |
| void | setGlobalSolveFunction (std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| | Sets a global backup function. More...
|
| |
| void | setFunction (const std::string &key, std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc) |
| | Register a callback function for a specific key. More...
|
| |
| void | setGetKeyFunction (std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> parseKeyFun) |
| | Set the callback function used to parse the key. More...
|
| |
| bool | startListen (const int &port, const int &threads=8) |
| | Start the HTTP server listening loop. More...
|
| |
| | ~HttpServer () |
| | Destructor. More...
|
| |
| void | putTask (const std::function< int(TcpFDHandler &k, TcpInformation &inf)> &fun, TcpFDHandler &k, TcpInformation &inf) |
| | Add a task to a worker thread pool and have it completed by worker threads. More...
|
| |
| | 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) |
| | Constructor. More...
|
| |
| bool | startListen (const int &port, const int &threads=8) |
| | Start the TCP server listening program. More...
|
| |
| bool | setTLS (const char *cert, const char *key, const char *passwd, const char *ca) |
| | Enable TLS encryption and configure server-side certificate and key. More...
|
| |
| void | redrawTLS () |
| | Revoke TLS encryption, CA certificate, etc. More...
|
| |
| void | setSecuritySendBackFun (std::function< void(TcpFDHandler &k, TcpInformation &inf)> fc) |
| | Set the callback invoked when an information security policy is violated. More...
|
| |
| void | setGlobalSolveFunction (std::function< bool(TcpFDHandler &k, TcpInformation &inf)> fc) |
| | Set global fallback function. More...
|
| |
| void | setFunction (const std::string &key, std::function< int(TcpFDHandler &k, TcpInformation &inf)> fc) |
| | Register a callback function for a specific key. More...
|
| |
| void | setGetKeyFunction (std::function< int(TcpFDHandler &k, TcpInformation &inf)> parseKeyFun) |
| | Set the callback function used to parse the key. More...
|
| |
| bool | stopListen () |
| | Stop listening. More...
|
| |
| bool | close () |
| | Close listening and all connected sockets. More...
|
| |
| virtual bool | close (const int &fd) |
| | Close the connection of a specific socket. More...
|
| |
| void | setCloseFun (std::function< void(const int &fd)> closeFun) |
| | set function after tcp connection close More...
|
| |
| bool | isListen () |
| | Return the listening status of the object. More...
|
| |
| SSL * | getSSL (const int &fd) |
| | Query the connection with the server, pass in the socket, and return the encrypted SSL handle. More...
|
| |
| | ~TcpServer () |
| | Destructor of TcpServer class. More...
|
| |
Http/HttpServer server operation class.
- Note
- support http/1.0 1.1
| stt::network::HttpServer::HttpServer |
( |
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 = 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 |
|
) |
| |
|
inline |
Constructor.
By default, allows up to 1,000,000 concurrent connections, allocates a maximum receive buffer of 256 KB per connection, and enables the security module.
- Note
- Enabling the security module introduces additional overhead and may impact performance.
- Parameters
-
| maxFD | Maximum number of connections this server instance can accept. Default: 1,000,000. |
| buffer_size | Maximum amount of data a single connection is allowed to receive, in kilobytes (KB). Default: 256 KB. |
| finishQueue_cap | The capacity of the worker completion queue (Worker → Reactor), which must be a power of 2. |
/ This queue holds the results of tasks completed by worker threads, waiting for reactor threads to consume them.
This is part of the main data path and is extremely sensitive to system throughput and latency.
/ Selection principle:
finishQueue_cap >= Peak completion rate (QPS) × worst-case reactor pause time
/ Suggested values (empirical):
- Low load/light business: 8192 (~8k)
- Regular high concurrency: 65536 (~64k) [Default]
- Extreme burst traffic: 131072 (~128k)
/ When the queue is full, requests will be dropped; the framework will not block the producer.
- Parameters
-
| security_open | Whether to enable the security module.
- true : enable security checks (default)
- false : disable security checks
|
| connectionNumLimit | Maximum number of concurrent connections allowed per IP. Default: 10. |
| connectionSecs | Time window (in seconds) for connection rate limiting. Default: 1 second. |
| connectionTimes | Maximum number of connection attempts allowed within connectionSecs seconds. Default: 3. |
| requestSecs | Time window (in seconds) for request rate limiting. Default: 1 second. |
| requestTimes | Maximum number of requests allowed within requestSecs seconds. Default: 20. |
| checkFrequency | Frequency (in seconds) for checking zombie/idle connections. -1 disables zombie connection detection. Default: 30 seconds. |
| connectionTimeout | If a connection has no activity for this many seconds, it is considered a zombie connection. -1 means no timeout (infinite). Default: 30 seconds. |