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