pthr_server_main_loop

NAME
SYNOPSIS
DESCRIPTION
AUTHOR
LICENSE
VERSION

NAME

pthr_server_main_loop, pthr_server_default_port, pthr_server_port_option_name, pthr_server_disable_syslog, pthr_server_package_name, pthr_server_disable_fork, pthr_server_disable_chdir, pthr_server_disable_close, pthr_server_chroot, pthr_server_username, pthr_server_stderr_file, pthr_server_startup_fn - Enter server main loop.

SYNOPSIS

#include <pthr_server.h>

void pthr_server_main_loop (int argc, char *argv[], void (*processor_fn) (int sock, void *));
void pthr_server_default_port (int default_port);
void pthr_server_port_option_name (char port_option_name);
void pthr_server_disable_syslog (void);
void pthr_server_package_name (const char *package_name);
void pthr_server_disable_fork (void);
void pthr_server_disable_chdir (void);
void pthr_server_disable_close (void);
void pthr_server_chroot (const char *root);
void pthr_server_username (const char *username);
void pthr_server_stderr_file (const char *pathname);
void pthr_server_startup_fn (void (*startup_fn) (int argc, char *argv[]));

DESCRIPTION

The function pthr_server_main_loop is a helper function which allows you to write very simple servers quickly using pthrlib. Normally your main should just contain a call to pthr_server_main_loop (argc, argv, processor) and you would include a function called processor which is called on every connection.
The other functions allow you to customise the behaviour of pthr_server_main_loop. You should call any of these once in your main before calling pthr_server_main_loop.
By default the server listens on port 80 and allows you to override this on the command line using the -p option. To change this, call pthr_server_default_port and/or pthr_server_port_option_name.
By default the server writes package and version information to syslog (although it will not be able to correctly determine the package). Use pthr_server_disable_syslog to disable syslogging entirely, or pthr_server_package_name to change the name displayed in the logs.
By default the server forks into the background, changes to the root directory and disconnects entirely from the terminal. Use pthr_server_disable_fork, pthr_server_disable_chdir and pthr_server_disable_close to change these respectively.
If you wish to have the server chroot after start up, then call pthr_server_chroot. This is only possible if the server is run as root, otherwise the chroot is silently ignored.
If you wish to have the server change user and group after start up, then call pthr_server_username (the group is taken from the password file and initgroups(3) is also called). This is only possible if the server is run as root, otherwise the change user is silently ignored.
If you wish to have stderr connected to a file (this is done after changing user, so make sure the file is accessible or owned by the user, not by root), then call pthr_server_stderr_file. Note that unless you call this function or pthr_server_disable_close then stderr is sent to /dev/null!
The startup_fn is called after all of the above operations have completed, but before the listener thread is created. You do miscellaneous start-of-day functions from here, in particular starting up other global threads. The command line arguments are also passed to this function.

AUTHOR

Richard Jones <rich@annexia.org>

LICENSE

GNU LGPL (see http://www.gnu.org/)

VERSION

pthrlib-3.0.3