2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#ifndef WEB_HTTP_SERVER_SERVERT_H
43#define WEB_HTTP_SERVER_SERVERT_H
45#include "web/http/server/SocketContextFactory.h"
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
54namespace web::http::
server {
56 template <
template <
typename SocketContextFactoryT,
typename... Args>
typename SocketServerT>
59 std::function<
void(
const std::shared_ptr<web::http::
server::
Request>&,
69 std::function<
void(
const std::shared_ptr<
Request>&,
const std::shared_ptr<
Response>&)>>;
79 std::function<
void(
const std::shared_ptr<
Request>&,
const std::shared_ptr<
Response>&)>&& onRequestReady)
80 :
Super(name, onConnect, onConnected, onDisconnect, std::forward<
decltype(onRequestReady)>(onRequestReady)) {
86 std::function<
void(
const std::shared_ptr<
Request>&,
const std::shared_ptr<
Response>&)>&& onRequestReady)
87 :
Server(
"", onConnect, onConnected, onDisconnect, std::forward<
decltype(onRequestReady)>(onRequestReady)) {
91 std::function<
void(
const std::shared_ptr<
Request>&,
const std::shared_ptr<
Response>&)>&& onRequestReady)
92 :
Super(name, std::forward<
decltype(onRequestReady)>(onRequestReady)) {
95 explicit Server(
const std::function<
void(
const std::shared_ptr<
Request>&, std::shared_ptr<
Response>&)>&& onRequestReady)
96 :
Server(
"", std::forward<
decltype(onRequestReady)>(onRequestReady)) {
#define APPLICATION(req, res)
virtual void acceptTimeout()
void signalEvent(int signum) override
AcceptEventReceiver(const std::string &name, const utils::Timeval &timeout)
virtual void acceptEvent()=0
void dispatchEvent() final
void timeoutEvent() final
Config & getConfig() const
State & operator&=(int state)
static constexpr int DISABLED
bool operator==(const int &state) const
State operator&(int state)
static constexpr int ERROR
static constexpr int FATAL
static constexpr int NO_RETRY
std::function< void(SocketConnection *)> onConnected
SocketConnectionT< PhysicalServerSocket, Config > SocketConnection
PhysicalSocketServerT PhysicalServerSocket
SocketAcceptor(const SocketAcceptor &socketAcceptor)
SocketAddress bindAddress
std::function< void(SocketConnection *)> onConnect
std::function< void(SocketConnection *)> onDisconnect
void unobservedEvent() final
std::shared_ptr< Config > config
virtual void useNextSocketAddress()=0
typename PhysicalServerSocket::SocketAddress SocketAddress
SocketAcceptor(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
~SocketAcceptor() override
PhysicalServerSocket physicalServerSocket
std::function< void(const SocketAddress &, core::socket::State)> onStatus
SocketAcceptorT SocketAcceptor
std::function< void(SocketConnection *)> & getOnConnect()
std::function< void(SocketConnection *)> setOnConnected(const std::function< void(SocketConnection *)> &onConnected, bool initialize=false)
SocketServer(Args &&... args)
void realListen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, unsigned int tries, double retryTimeoutScale) const
SocketServer(const std::string &name, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
typename SocketAcceptor::SocketAddress SocketAddress
SocketServer(const std::string &name, Args &&... args)
std::function< void(SocketConnection *)> onConnect
SocketServer(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
std::function< void(SocketConnection *)> setOnConnect(const std::function< void(SocketConnection *)> &onConnect, bool initialize=false)
std::function< void(SocketConnection *)> & getOnDisconnect()
core::socket::Socket< typename SocketAcceptor::Config > Super
std::function< void(SocketConnection *)> setOnDisconnect(const std::function< void(SocketConnection *)> &onDisconnect, bool initialize=false)
std::function< void(SocketConnection *)> onDisconnect
void listen(const SocketAddress &localAddress, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(const SocketAddress &localAddress, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::shared_ptr< SocketContextFactory > socketContextFactory
void listen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::function< void(SocketConnection *)> onConnected
typename SocketAcceptor::SocketConnection SocketConnection
std::function< void(SocketConnection *)> & getOnConnected()
SocketContextFactoryT SocketContextFactory
std::shared_ptr< SocketContextFactory > getSocketContextFactory()
SocketServer(const std::shared_ptr< Config > &config, const std::shared_ptr< SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect)
typename SocketAcceptor::Config Config
void useNextSocketAddress() override
typename Super::Config Config
typename Super::SocketAddress SocketAddress
typename Super::SocketConnection SocketConnection
core::socket::stream::SocketAcceptor< PhysicalServerSocketT, ConfigT, core::socket::stream::legacy::SocketConnection > Super
SocketAcceptor(const SocketAcceptor &socketAcceptor)
SocketAcceptor(const std::shared_ptr< core::socket::stream::SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
static Timer singleshotTimer(const std::function< void()> &dispatcher, const utils::Timeval &timeout)
Controller(const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
void send(const std::string &chunk)
WebAppT(const std::string &name, const Router &router)
typename Server::SocketConnection SocketConnection
express::Response Response
typename Server::SocketAddress SocketAddress
WebAppT(const std::string &name)
static void init(int argc, char *argv[])
static core::TickStatus tick(const utils::Timeval &timeOut=0)
static core::State state()
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
WebApp(const Router &router)
const std::string & getInstanceName() const
ConfigPhysicalSocketServer(ConfigInstance *instance)
utils::Timeval getAcceptTimeout() const
CLI::Option * acceptTimeoutOpt
ConfigPhysicalSocketServer & setAcceptTimeout(const utils::Timeval &acceptTimeout)
CLI::Option * acceptsPerTickOpt
ConfigPhysicalSocketServer & setBacklog(int newBacklog)
int getAcceptsPerTick() const
ConfigPhysicalSocketServer Socket
ConfigPhysicalSocket Super
ConfigPhysicalSocketServer & setAcceptsPerTick(int acceptsPerTickSet)
ConfigAddressRemoteT< net::config::ConfigAddressReverse > Remote
ConfigSocketServer(net::config::ConfigInstance *instance)
ConfigAddressLocalT< net::config::ConfigAddressLocal > Local
ConfigSocketServer(const std::string &name)
std::string toString(bool expanded=true) const override
PhysicalSocketServer(PhysicalSocketServer &&) noexcept=default
net::in::phy::stream::PhysicalSocket< net::phy::stream::PhysicalSocketServer > Super
~PhysicalSocketServer() override
void listen(const std::string &ipOrHostname, uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(const std::string &ipOrHostname, uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
core::socket::stream:: SocketServer< SocketAcceptorT< net::in::phy::stream::PhysicalSocketServer, ConfigSocketServerT >, SocketContextFactoryT, Args... > Super
~ConfigSocketServer() override
CLI::Option * disableNagleAlgorithmOpt
bool getReusePort() const
ConfigSocketServer & setReusePort(bool reusePort=true)
bool getReuseAddress() const
bool getDisableNagleAlgorithm() const
ConfigSocketServer & setReuseAddress(bool reuseAddress=true)
ConfigSocketServer(net::config::ConfigInstance *instance)
CLI::Option * reusePortOpt
ConfigSocketServer & setDisableNagleAlgorithm(bool disableNagleAlgorithm=true)
CLI::Option * reuseAddressOpt
~ConfigSocketServer() override
ConfigSocketServer(const std::string &name)
net::phy::stream::PhysicalSocket< SocketAddressT > Super
SocketAddressT SocketAddress
void getAttribute(const std::function< void(Attribute &)> &onFound, const std::function< void(const std::string &)> &onNotFound, const std::string &subKey="") const
static double getInRange(double ll, double ul)
Timeval(const std::initializer_list< time_t > &initList) noexcept
Server(const std::string &name, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
Server(const std::string &name, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
SocketServerT< web::http::server::SocketContextFactory, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> > Super
typename SocketConnection::SocketAddress SocketAddress
Server(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
Server(const std::function< void(const std::shared_ptr< Request > &, std::shared_ptr< Response > &)> &&onRequestReady)
web::http::server::Request Request
web::http::server::Response Response
typename Super::SocketConnection SocketConnection
int main(int argc, char *argv[])
SocketServer Server(const std::string &instanceName, const std::function< void(typename SocketServer::Config &)> &configurator, Args &&... socketContextFactoryArgs)
SocketServer Server(const std::string &instanceName, Args &&... socketContextFactoryArgs)
SocketServer< SocketContextFactory, SocketContextFactoryArgs... > Server(const std::string &instanceName, const std::function< void(typename SocketServer< SocketContextFactory, SocketContextFactoryArgs... >::Config &)> &configurator, SocketContextFactoryArgs &&... socketContextFactoryArgs)
SocketServer< SocketContextFactory, SocketContextFactoryArgs... > Server(const std::string &instanceName, SocketContextFactoryArgs &&... socketContextFactoryArgs)
net::in::stream::SocketServer< core::socket::stream::legacy::SocketAcceptor, net::in::stream::legacy::config::ConfigSocketServer, SocketContextFactoryT, Args... > SocketServer
web::http::server::Server< net::in::stream::legacy::SocketServer > Server