Async Http Server. More...
#include <HttpAsyncServer.h>
Public Member Functions | |
| template<typename T , typename = typename TypeTraits::EnableIf<TypeTraits::IsBaseOf<HttpConnection, T>::value>::type> | |
| Result | init (Span< T > clients) |
| Initializes the async server with all needed memory buffers. | |
| template<typename T , typename = typename TypeTraits::EnableIf<TypeTraits::IsBaseOf<HttpConnection, T>::value>::type> | |
| Result | resize (Span< T > clients) |
| Result | close () |
| Closes the server, removing references to the memory buffers passed during init. | |
| Result | start (AsyncEventLoop &loop, StringSpan address, uint16_t port) |
| Starts the http server on the given AsyncEventLoop, address and port. | |
| Result | stop () |
| Stops http server asynchronously pushing cancel and close requests to the event loop. | |
| void | setMaxHeaderSize (uint32_t bytes) |
| Sets the maximum accepted request-header size in bytes. | |
| uint32_t | getMaxHeaderSize () const |
| Gets the maximum accepted request-header size in bytes. | |
| bool | isStarted () const |
| Returns true if the server has been started. | |
| const HttpConnectionsPool & | getConnections () const |
| void | setDefaultKeepAlive (bool enabled) |
| Set default keep-alive behavior for all connections. | |
| bool | getDefaultKeepAlive () const |
| Get the default keep-alive setting. | |
| void | setMaxRequestsPerConnection (uint32_t maxRequests) |
| Set maximum requests per keep-alive connection. | |
| uint32_t | getMaxRequestsPerConnection () const |
| Get the maximum requests per connection. | |
Public Attributes | |
| Function< void(HttpConnection &)> | onRequest |
| Called after enough data from a newly connected client has arrived, causing all headers to be parsed. | |
| Function< void(Result)> | onError |
| Called on accept, parse, protocol, or streaming errors before the affected connection is closed. | |
Async Http Server.
This class handles a fully asynchronous http server staying inside 5 fixed memory regions passed during init.
Usage:
| Result SC::HttpAsyncServer::close | ( | ) |
Closes the server, removing references to the memory buffers passed during init.
|
inlinenodiscard |
Get the default keep-alive setting.
|
inlinenodiscard |
Gets the maximum accepted request-header size in bytes.
|
inlinenodiscard |
Get the maximum requests per connection.
|
inline |
Initializes the async server with all needed memory buffers.
|
inlinenodiscard |
Returns true if the server has been started.
|
inline |
Set default keep-alive behavior for all connections.
| enabled | true to keep connections alive by default (HTTP/1.1 default) |
|
inline |
Sets the maximum accepted request-header size in bytes.
The limit must fit inside the per-connection header storage passed to init().
|
inline |
Set maximum requests per keep-alive connection.
| maxRequests | Maximum requests before closing connection (0 = unlimited) |
| Result SC::HttpAsyncServer::start | ( | AsyncEventLoop & | loop, |
| StringSpan | address, | ||
| uint16_t | port ) |
Starts the http server on the given AsyncEventLoop, address and port.
| loop | The event loop to be used, where to add the listening socket |
| address | The address of local interface where to listen to |
| port | The local port where to start listening to |
| Result SC::HttpAsyncServer::stop | ( | ) |
Stops http server asynchronously pushing cancel and close requests to the event loop.
Called on accept, parse, protocol, or streaming errors before the affected connection is closed.
| Function<void(HttpConnection&)> SC::HttpAsyncServer::onRequest |
Called after enough data from a newly connected client has arrived, causing all headers to be parsed.