![]() |
Jazz 1.25.+
|
HttpServer: The http server is also a Service. More...
#include <server.h>
Public Member Functions | |
HttpServer (pLogger a_logger, pConfigFile a_config) | |
virtual pChar const | id () |
StatusCode | start (pSignalHandler p_sig_handler, pMHD_Daemon &p_daemon, MHD_AccessHandlerCallback dh, Channels &channels) |
StatusCode | shut_down () |
![]() | |
Service (pLogger a_logger, pConfigFile a_config) | |
virtual StatusCode | start () |
A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start()) | |
void | log (int loglevel, const char *message) |
void | log_printf (int loglevel, const char *fmt,...) |
bool | get_conf_key (const char *key, int &value) |
bool | get_conf_key (const char *key, double &value) |
bool | get_conf_key (const char *key, std::string &value) |
Private Attributes | |
int | http_port = 0 |
The port the server is listening to. | |
MHD_OptionItem | server_options [9] |
Variadic parameter MHD_OPTION_ARRAY, server_options, MHD_OPTION_END in MHD_start_daemon() | |
Additional Inherited Members | |
![]() | |
pLogger | p_log |
The logger. | |
pConfigFile | p_conf |
The configuration file. | |
HttpServer: The http server is also a Service.
jazz_main::HttpServer::HttpServer | ( | pLogger | a_logger, |
pConfigFile | a_config | ||
) |
Constructor for the HttpServer service.
a_logger | A pointer to the Logger object. |
a_config | A pointer to the ConfigFile object. |
|
virtual |
Return object ID.
Reimplemented from jazz_elements::Service.
StatusCode jazz_main::HttpServer::start | ( | pSignalHandler | p_sig_handler, |
pMHD_Daemon & | p_daemon, | ||
MHD_AccessHandlerCallback | dh, | ||
Channels & | channels | ||
) |
Start the Jazz server.
p_sig_handler | A function (of type pSignalHandler) that will be called when the process receives a SIGTERM signal. |
p_daemon | Returns by reference the pointer that will be used to control the MHD_Daemon. |
dh | The address of the MHD_AccessHandlerCallback (server callback). |
channels | The instance of Channel to find out the configuration port. |
Starting logic:
Get all the MHD server config settings via get_conf_key()
The default config file is JAZZ_DEFAULT_CONFIG_PATH but that can be changed via command line argument (see jazz_main.cpp).
Calls MHD_start_daemon()
Then calls setsid() This creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session, the process group leader of the new process group, and has no controlling terminal.
And sleeps forever! (Remember, it is the child of the original caller who exited with EXIT_SUCCESS.)
|
virtual |
Server closing method.
This overrides the Service shut_down() just to set the return to SERVICE_NO_ERROR.
The true closing mechanism is a: MHD_stop_daemon (Jazz_MHD_Daemon); done by the signalHandler_SIGTERM() callback that captures SIGTERM.
Reimplemented from jazz_elements::Service.