COROIO: NNet::TWebServer< TSocket > Class Template Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TWebServer< TSocket > Class Template Reference

HTTP/1.1 server that accepts connections and dispatches to a router. More...

#include <httpd.hpp>

Public Member Functions

 TWebServer (TSocket &&serverSocket, IRouter &router, std::function< void(const std::string &)> logger={})
 Constructs the server.
 
TVoidTask Start ()
 Starts the accept loop as a detached TVoidTask.
 

Detailed Description

template<typename TSocket>
class NNet::TWebServer< TSocket >

HTTP/1.1 server that accepts connections and dispatches to a router.

Takes ownership of a bound, listening socket. Call Start() to launch the accept loop as a detached TVoidTask.

Template Parameters
TSocketA bound+listening socket type (e.g. TDefaultPoller::TSocket).
TSocket sock(loop.Poller(), addr.Domain());
sock.Bind(addr); sock.Listen();
MyRouter router;
TWebServer<TSocket> server(std::move(sock), router);
server.Start();
loop.Loop();
NNet::TSocket TSocket
Alias for the socket type.
Definition poll.hpp:42
High-level asynchronous socket for network communication.
Definition socket.hpp:367
HTTP/1.1 server that accepts connections and dispatches to a router.
Definition httpd.hpp:237

Constructor & Destructor Documentation

◆ TWebServer()

template<typename TSocket >
NNet::TWebServer< TSocket >::TWebServer ( TSocket &&  serverSocket,
IRouter router,
std::function< void(const std::string &)>  logger = {} 
)
inline

Constructs the server.

Parameters
serverSocketBound, listening socket (moved in; owned by the server).
routerRequest handler; must outlive this server.
loggerOptional nginx-style access-log callback.

Member Function Documentation

◆ Start()

template<typename TSocket >
TVoidTask NNet::TWebServer< TSocket >::Start ( )
inline

Starts the accept loop as a detached TVoidTask.

Runs forever, accepting connections and spawning a per-connection handler coroutine for each. Returns immediately (the loop is detached).


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