|
STTNet
|
Http/HttpServer server operation class. More...
#include <sttnet_English.h>
Public Member Functions | |
| 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 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... | |
Public Member Functions inherited from stt::network::TcpServer | |
| 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 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... | |
Additional Inherited Members | |
Protected Attributes inherited from 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 server operation class.
|
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.
| 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. |
| security_open | Whether to enable the security module.
|
| 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. |
|
inline |
Destructor.
| void stt::network::HttpServer::putTask | ( | const std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> & | fun, |
| HttpServerFDHandler & | k, | ||
| HttpRequestInformation & | inf | ||
| ) |
Submit a task to the worker thread pool.
| fun | The callable object to be executed by the worker thread pool.
|
| k | Reference to the socket operation object associated with the client connection. |
| inf | Reference to the client request information. |
|
inline |
Register a callback function for a specific key.
| key | The key used to locate the corresponding callback functions. |
| fc | A function or function object that defines the logic for handling client requests.
|
|
inline |
Set the callback function used to parse the key.
| parseKeyFun | The callback function used to parse the key.
|
|
inline |
Sets a global backup function.
| fc | A function or function object used for processing logic after receiving a message from the client. |
HttpRequestInformation &inf - Client information, saved data, processing progress, state machine information, etc.
|
inline |
Set the callback invoked when an information security policy is violated.
This callback is executed when a client violates a security rule (e.g. rate limiting, abnormal request behavior, or other security checks). After the callback is executed, the connection will be closed.
| fc | A function or function object used to handle the response sent back to the client upon a security violation. |
Callback parameters:
|
inline |
Start the HTTP server listening loop.
| port | The port to listen on. |
| threads | Number of worker/consumer threads (default: 8). |
1.8.5