STTNet
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Public Member Functions | List of all members
stt::network::HttpServer Class Reference

Http/HttpServer server operation class. More...

#include <sttnet_English.h>

Inheritance diagram for stt::network::HttpServer:
stt::network::TcpServer

Public Member Functions

 HttpServer (const int &maxFD=10000000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=60)
 Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to 20; The fastest connection speed per second for the same IP address is 6. More...
 
bool setFunction (std::function< bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc)
 Set a callback function for responding after receiving and successfully parsing an Http/Https request Register a callback function. More...
 
- Public Member Functions inherited from stt::network::TcpServer
 TcpServer (const int &maxFD=10000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=1800)
 Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to 20; The fastest connection speed per second for the same IP address is 6. 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...
 
bool setFunction (std::function< bool(TcpFDHandler &k, TcpFDInf &inf)> fc)
 Set the callback function after receiving a message from the client Register a callback function. More...
 
bool stopListen ()
 Stop listening. More...
 
bool close ()
 Close listening and all connected sockets. More...
 
bool close (const int &fd)
 Close the connection of a specific socket. 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 Member Functions inherited from stt::network::TcpServer
bool allowRequest (const int &cclientfd)
 
void connectionDetect ()
 
- Protected Attributes inherited from stt::network::TcpServer
unsigned long buffer_size
 
int maxFD
 
security::ConnectionLimiter connectionLimiter
 
TcpFDInfclientfd
 
int flag1 = true
 
std::queue< QueueFD > * fdQueue
 
std::mutex * lq1
 
std::condition_variable * cv
 
int consumerNum
 
std::mutex lco1
 
bool unblock
 
SSL_CTX * ctx = nullptr
 
bool TLS = false
 
int requestRate
 
int checkFrequency
 
int connectionTimeout
 
bool security_open
 

Detailed Description

Http/HttpServer server operation class.

Note
support http/1.0 1.1

Constructor & Destructor Documentation

stt::network::HttpServer::HttpServer ( const int &  maxFD = 10000000,
const bool &  security_open = true,
const int &  connectionNumLimit = 20,
const int &  connectionRateLimit = 6,
const int &  buffer_size = 8,
const int &  requestRate = 12,
const int &  checkFrequency = 1,
const int &  connectionTimeout = 60 
)
inline

Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to 20; The fastest connection speed per second for the same IP address is 6.

Note
Turning on the security module has a performance impact
Parameters
maxFDservice object can accept the maximum number of connections
security_opentrue: enable the security module false: disable the security module (enabled by default)
connectionNumLimitThe maximum number of connections from the same IP address
connectionRateLimitThe maximum number of connections per second to the same IP address
buffer_sizeThe maximum amount of data allowed to be transferred over the same connection (in KB) is 8KB by default
requestRatteThe maximum number of requests allowed in one second for the same connection (the default is 12 times)
checkFrequencyThe frequency of checking zombie connections (in minutes) The default is 1 minute -1 means no check
connectionTimeoutThe number of seconds that a connection is considered a zombie connection if there is no response (in seconds) The default is 60 seconds -1 means no limit

Member Function Documentation

bool stt::network::HttpServer::setFunction ( std::function< bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)>  fc)
inline

Set a callback function for responding after receiving and successfully parsing an Http/Https request Register a callback function.

Parameters
fcA function or function object for the callback function to respond after receiving and successfully parsing an Http/Https request
Note
The passed function should have the signature bool func(const HttpRequestInformation &inf, HttpServerFDHandler &k)
If processing fails, the connection will be closed

The documentation for this class was generated from the following file: