dot-xx
A personal collection of small C++ modules
|
A simple HTTP server. More...
Public Types | |
using | DispatcherImmediate = std::function<void(const Request&, Response&)> |
A callback type for requests that return their response immediately. | |
using | DispatcherDelayed |
A callback type for requests that assume ownership over the connection to be processed later. | |
using | Dispatcher = std::variant<DispatcherImmediate, DispatcherDelayed> |
A generalized response callback type. |
Public Member Functions | |
SimpleTask | listen_and_wait (const std::string &ip, u16 port) |
Run the server life cycle as a coroutine. | |
void | listen (const std::string &ip, u16 port) |
Run the server life cycle. Self-explanatory. | |
void | request_stop () |
Interrupt the server listen loop on the next iteration. | |
void | bind (Method method, const std::filesystem::path &path, const Dispatcher &cb) |
Bind a callback to process the request. |
A simple HTTP server.
A callback type for requests that assume ownership over the connection to be processed later.
void dxx::http::Server::listen | ( | const std::string & | ip, |
u16 | port ) |
Run the server life cycle. Self-explanatory.
ip | IP to bind to, uses std::string instead of std::string_view because we want to ensure it is null-terminated (couldn't find it in the man, just to be safe) |
port | server port |
SimpleTask dxx::http::Server::listen_and_wait | ( | const std::string & | ip, |
u16 | port ) |
Run the server life cycle as a coroutine.
Before serving each next connection, is suspends to allow the program to do some other work or to allow to gracefully shut down the server
ip | IP to bind to, uses std::string instead of std::string_view because we want to ensure it is null-terminated (couldn't find it in the man, just to be safe) |
port | server port |