![]() |
zeep::http::daemon — A class to create daemon processes easily.
// In header: <zeep/http/daemon.hpp> class daemon { public: // types typedef std::function< server *()> server_factory_type; // The factory for creating server instances. // construct/copy/destruct daemon(server_factory_type &&, const std::string &, const std::string &, const std::string &); daemon(server_factory_type &&, const char *); // public member functions void set_max_restarts(int, int); int start(const std::string &, uint16_t, size_t, size_t, const std::string &); int stop(); int status(); int reload(); int run_foreground(const std::string &, uint16_t); // private member functions void daemonize(); void open_log_file(); bool run_main_loop(const std::string &, uint16_t, size_t, size_t, const std::string &); bool pid_is_for_executable(); };
In UNIX a daemon is a process that runs in the background. In the case of libzeep this is of course serving HTTP requests. stderr and stdout are captured and written to the log files specified and a process ID is store in the pid file which allows checking the status of a running daemon.
daemon
public
construct/copy/destructdaemon(server_factory_type && factory, const std::string & pid_file, const std::string & stdout_log_file, const std::string & stderr_log_file);constructor with separately specified files
Parameters: |
|
daemon(server_factory_type && factory, const char * name);constructor with default files
Parameters: |
|
daemon
public member functionsvoid set_max_restarts(int nr_of_restarts, int within_nr_of_seconds);Avoid excessive automatic restart due to failing to start up.
Parameters: |
|
int start(const std::string & address, uint16_t port, size_t nr_of_procs, size_t nr_of_threads, const std::string & run_as_user);Start the daemon, forking off in the background.
Parameters: |
|
int stop();Stop a running daemon process. Returns 0 in case of successfully stopping a process.
int status();Returns 0 if the daemon is running.
int reload();Force the running daemon to restart.
int run_foreground(const std::string & address, uint16_t port);Run the server without forking to the background.
For debugging purposes it is sometimes useful to start a server without forking so you can see the stdout and stderr. Often this is done by adding a –no-daemon flag to the program options.