HANDLER_LISTEN(3)

NAME
handler_listen - listen to and handle incoming connections on a web server

SYNOPSIS

#include <slweb/handler.h>

int handler_listen(struct handler *h, unsigned short port);

DESCRIPTION
The handler_listen(3) function listens for connections on the TCP port number given by port on a struct handler object pointed to by h, which must be previously allocated by a call to handler_alloc(3). Also, the handler_listen(3) function validates incoming requests and calls the configured callbacks previously given by one or more calls to handler_add(3). The handler_listen(3) function blocks until either SIGTERM or SIGINT are triggered.

RETURN VALUE
On success, zero is returned. On error, a negative integer is returned.

ERRORS
No errors are defined.

FUTURE DIRECTIONS
When no configured endpoint matches the incoming request, slweb shall respond with a 404 Not Found HTTP status code with no payload. Since some library users might want to provide custom pages for such error condition, future versions of this library shall replace the harcoded response with an additional callback on struct handler_cfg, similarly to its member length.

SEE ALSO
handler_alloc(3), handler_free(3), handler_add(3), slweb_handler(7), signal(7).

COPYRIGHT
Copyright (C) 2023 Xavier Del Campo Romero.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.