16 _server(std::make_shared<restbed::
Service>()),
17 _settings(std::make_shared<restbed::Settings>()),
20 assert((
service !=
nullptr) &&
"ASIO service is invalid!");
22 throw CppCommon::ArgumentException(
"ASIO service is invalid!");
25 _server->set_external_io_service(_service->service());
28 _settings->set_port(port);
33 _server(std::make_shared<restbed::
Service>()),
34 _settings(std::make_shared<restbed::Settings>()),
37 assert((
service !=
nullptr) &&
"ASIO service is invalid!");
39 throw CppCommon::ArgumentException(
"ASIO service is invalid!");
42 _server->set_external_io_service(_service->service());
45 _settings->set_bind_address(address);
46 _settings->set_port(port);
51 assert(!
IsStarted() &&
"Web server is already started!");
56 auto self(this->shared_from_this());
57 _service->service()->post([
this,
self]()
60 _server->start(_settings);
74 assert(
IsStarted() &&
"Web server is not started!");
79 auto self(this->shared_from_this());
80 _service->service()->post([
this,
self]()
101 CppCommon::Thread::Yield();
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
HTTP Web server definition.
C++ Server project definitions.
virtual void onStarted()
Handle server started notification.
WebServer(std::shared_ptr< Service > service, int port)
Initialize HTTP Web server with a given Asio service and port number.
bool IsStarted() const noexcept
Is the server started?
bool Restart()
Restart the server.
virtual void onStopped()
Handle server stopped notification.
bool Start()
Start the server.
bool Stop()
Stop the server.