Async Http server. More...
#include <HttpServer.h>
Public Member Functions | |
| HttpServer (const HttpServer &)=delete | |
| HttpServer & | operator= (const HttpServer &)=delete |
| HttpServer (HttpServer &&)=delete | |
| HttpServer & | operator= (HttpServer &&)=delete |
| Result | start (AsyncEventLoop &loop, uint32_t maxConcurrentRequests, StringSpan address, uint16_t port) |
| Starts the http server on the given AsyncEventLoop, address and port. | |
| Result | stopAsync () |
| Stops http server asynchronously pushing cancel and close requests for next SC::AsyncEventLoop::runOnce. | |
| Result | stopSync () |
| Stops http server synchronously waiting for SC::AsyncEventLoop::runNoWait to cancel or close all requests. | |
| bool | isStarted () const |
| Check if the server is started. | |
| HttpRequest * | getRequest (ArenaMapKey< HttpServerClient > key) const |
| Obtain client request (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey. | |
| HttpResponse * | getResponse (ArenaMapKey< HttpServerClient > key) const |
| Obtain client response (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey. | |
| SocketDescriptor * | getSocket (ArenaMapKey< HttpServerClient > key) const |
| Obtain client socket (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey. | |
| uint32_t | getMaxConcurrentRequests () const |
| Return maximum number of concurrent requests, corresponding to size of clients arena. | |
Public Attributes | |
| Function< void(HttpRequest &, HttpResponse &)> | onRequest |
| Called after enough data from a newly connected client has arrived, causing all headers to be parsed. | |
Async Http server.
Usage:
|
nodiscard |
Return maximum number of concurrent requests, corresponding to size of clients arena.
|
nodiscard |
Obtain client request (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey.
|
nodiscard |
Obtain client response (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey.
|
nodiscard |
Obtain client socket (or a nullptr if it doesn't exists) with the key returned by SC::HttpResponse::getClientKey.
|
nodiscard |
Check if the server is started.
| Result SC::HttpServer::start | ( | AsyncEventLoop & | loop, |
| uint32_t | maxConcurrentRequests, | ||
| 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 |
| maxConcurrentRequests | Maximum number of concurrent requests |
| address | The address of local interface where to listen to |
| port | The local port where to start listening to |
| Result SC::HttpServer::stopAsync | ( | ) |
Stops http server asynchronously pushing cancel and close requests for next SC::AsyncEventLoop::runOnce.
| Result SC::HttpServer::stopSync | ( | ) |
Stops http server synchronously waiting for SC::AsyncEventLoop::runNoWait to cancel or close all requests.
| Function<void(HttpRequest&, HttpResponse&)> SC::HttpServer::onRequest |
Called after enough data from a newly connected client has arrived, causing all headers to be parsed.