|
| void | putTask (const std::function< int(WebSocketServerFDHandler &, WebSocketFDInformation &)> &fun, WebSocketServerFDHandler &k, WebSocketFDInformation &inf) |
| | Submit a task to the worker thread pool. More...
|
| |
| | WebSocketServer (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=5, const int &connectionSecs=10, const int &connectionTimes=3, const int &requestSecs=1, const int &requestTimes=10, const int &checkFrequency=60, const int &connectionTimeout=120) |
| | Constructor. More...
|
| |
| void | setSecuritySendBackFun (std::function< void(WebSocketServerFDHandler &k, WebSocketFDInformation &inf)> fc) |
| | Set the callback invoked when an information security policy is violated. More...
|
| |
| void | setGlobalSolveFunction (std::function< bool(WebSocketServerFDHandler &, WebSocketFDInformation &)> fc) |
| | Set the global fallback handler. More...
|
| |
| void | setStartFunction (std::function< bool(WebSocketServerFDHandler &, WebSocketFDInformation &)> fccc) |
| | Set the callback invoked immediately after a WebSocket connection is established. More...
|
| |
| void | setJudgeFunction (std::function< bool(WebSocketFDInformation &)> fcc) |
| | Set the handshake validation callback. More...
|
| |
| void | setFunction (const std::string &key, std::function< int(WebSocketServerFDHandler &, WebSocketFDInformation &)> fc) |
| | Register a message handler callback for a specific key. More...
|
| |
| void | setGetKeyFunction (std::function< int(WebSocketServerFDHandler &, WebSocketFDInformation &)> parseKeyFun) |
| | Set the key parsing callback. More...
|
| |
| void | setTimeOutTime (const int &seca) |
| | Set heartbeat interval. More...
|
| |
| void | setHBTimeOutTime (const int &secb) |
| | Set heartbeat response timeout. More...
|
| |
| bool | closeFD (const int &fd, const std::string &closeCodeAndMessage) |
| | Close a WebSocket connection using an encoded close payload. More...
|
| |
| bool | closeFD (const int &fd, const short &code=1000, const std::string &message="bye") |
| | Close a WebSocket connection using standard RFC 6455 format. More...
|
| |
| bool | sendMessage (const int &fd, const std::string &msg, const std::string &type="0001") |
| | Send a WebSocket message to a specific client. More...
|
| |
| bool | close () |
| | Close all connections and stop listening. More...
|
| |
| bool | close (const int &fd) |
| | Close the connection of a certain socket More...
|
| |
| bool | startListen (const int &port, const int &threads=8) |
| | Start the WebSocket server. More...
|
| |
| void | sendMessage (const std::string &msg, const std::string &type="0001") |
| | Broadcast a WebSocket message to all connected clients. More...
|
| |
| | ~WebSocketServer () |
| | 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...
|
| |
| 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...
|
| |
WebSocketServer server operation class.
| stt::network::WebSocketServer::WebSocketServer |
( |
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 = 5, |
|
|
const int & |
connectionSecs = 10, |
|
|
const int & |
connectionTimes = 3, |
|
|
const int & |
requestSecs = 1, |
|
|
const int & |
requestTimes = 10, |
|
|
const int & |
checkFrequency = 60, |
|
|
const int & |
connectionTimeout = 120 |
|
) |
| |
|
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: 5. |
| connectionSecs | Time window (in seconds) for connection rate limiting. Default: 10 seconds. |
| connectionTimes | Maximum number of connection attempts allowed within connectionSecs seconds. Default: 3. |
| requestSecs | Time window (in seconds) for request/message rate limiting. Default: 1 second. |
| requestTimes | Maximum number of requests/messages allowed within requestSecs seconds. Default: 10. |
| checkFrequency | Frequency (in seconds) for checking zombie/idle connections. -1 disables zombie connection detection. Default: 60 seconds. |
| connectionTimeout | If a connection has no activity for this many seconds, it is considered a zombie connection. -1 means no timeout (infinite). Default: 120 seconds. |