aboutsummaryrefslogtreecommitdiff
path: root/server.c
Commit message (Collapse)AuthorAgeFilesLines
* Allow custom backlog connectionsXavier Del Campo Romero2025-10-061-4/+12
| | | | | | | | | libweb calls listen(2) when setting up the HTTP server, and its backlog argument was hardcoded to 10. While probably not an issue for some applications, it can be too limiting for some others. Therefore, it is desirable to allow library users to set up their own limits. Otherwise, 10 is still chosen as a sane default.
* server.c: Fix wrong for loop rangev0.4.1Xavier Del Campo Romero2024-08-281-1/+1
|
* server.c: Multiplex client eventsXavier Del Campo Romero2024-08-251-4/+15
| | | | | | | Future commits would allow user-defined callbacks to write zero, one or more bytes to a file descriptor. If zero bytes were written, server_poll must avoid to always point to the same server_client, so that other requests from other server_client instances can still be handled.
* server.c: Fix descriptor leak on failed fcntl(2)Xavier Del Campo Romero2024-08-251-8/+14
|
* Move signal handling to processesXavier Del Campo Romero2024-08-221-89/+74
| | | | | | | | | | | | | | So far, libweb installed a signal handler so as to handle SIGTERM, SIGPIPE and SIGINT signals so that processes would not have to care about such details. However, it is not advisable for libraries to install signal handlers, as signals are handled on a per-process basis. The previous approach would be incompatible if several instances of the library were allocated by the same process. Unfortunately, this has the undesired side effect of adding the boilerplate code into the process.
* server.c: Fix wrong priority for do_exitXavier Del Campo Romero2024-01-201-6/+6
| | | | | | Under some specific circumstances, poll(2) would return a positive integer, but do_exit might had been previously set. This caused libweb to ignore SIGTERM, with the potential risk for an endless loop.
* Merge pull request 'Fix double-free on failed `server_client_close`' (#2) ↵xavi2023-11-201-1/+0
|\ | | | | | | | | | | from midokura-xavi/libweb:fix-double-free into master Reviewed-on: https://gitea.privatedns.org/xavi/libweb/pulls/2
| * Fix double-free on failed server_client_closeXavier Del Campo2023-11-201-1/+0
| | | | | | | | | | Even if server_client_close fails, it is needed for client_free to remove the dangling reference from h->clients.
* | Split handler_loop from handler_listenXavier Del Campo2023-11-201-2/+4
|/ | | | | | | | | | | | | | Some applications might set up a struct handler object to listen on any port i.e., 0, but still need a way to determine which port number was eventually selected by the implementation. Therefore, handler_listen has been reduced to the server initialization bit, whereas the main loop has been split into its own function, namely handler_loop. Because of these changes, it no longer made sense for libweb to write the selected port to standard output, as this is something now applications can do on their own.
* Rename project from slweb to libwebv0.1.0-rc3Xavier Del Campo Romero2023-10-111-1/+1
| | | | | | | | | | | | It was found out there was another project of the same name around (https://git.sr.ht/~strahinja/slweb/), also related to website generation. In order to avoid confusion, a new name has been chosen for this project. Surprisingly, libweb was not in use by any distributions (according to https://repology.org and AUR index), and it should reflect well the intention behind this project i.e., being a library to build web-related stuff.
* server.c: Replace sequential calls with loopXavier Del Campo Romero2023-10-101-14/+18
|
* server.c: Fix build on FreeBSDXavier Del Campo Romero2023-09-261-0/+6
|
* Move header files to subdirectoryXavier Del Campo Romero2023-07-211-1/+1
| | | | | | | | | | | Since slweb is meant as a library, it is advisable to keep public header files under their own directory in order to avoid name clashing i.e., #include "something.h" Now becomes: #include "slweb/something.h"
* server.c: Fix typoXavier Del Campo Romero2023-07-201-1/+1
|
* server.c: Fix undefined behaviour on >1 clientsXavier Del Campo Romero2023-07-201-45/+45
| | | | | | | | | | | | | | server.c kept an array of all of its active clients, calling realloc(3) everytime its size had to be modified. However, reallocating this array had the undesired consequence of moving other active clients to other memory locations. Potentially, this would result in dangling pointers from other components that also kept pointers to struct server_client instances e.g.: handler.c. For this reason, the array-based approach has been completely dropped, in favour of a doubly-linked list.
* Avoid crashing on SIGPIPEXavier Del Campo Romero2023-07-201-2/+18
| | | | | | | | | Under some circumstances, clients could cause SIGPIPE to slcl. Since this signal was not handled by server.c (i.e., via sigaction(3)), slcl would crash without any error messages printed to stderr. In such situation, SIGPIPE should not be usually considered a fatal error, so it is preferrable to close the connection and keep working.
* Replace select(2) with poll(2)Xavier Del Campo Romero2023-07-201-26/+65
| | | | | | select(2) has a number of well-known issues (e.g.: FD_SETSIZE limiting the maximum amount of file descriptors to watch) that are mostly solved by poll(2) and thus can be used as a drop-in replacement.
* Define _POSIX_C_SOURCEXavier Del Campo Romero2023-07-201-0/+2
| | | | | This allows using the default compiler defined by make(1) (i.e., c99(1)), thus improving POSIX compatibility.
* server.c: Fix wrong size for memcpy(3)Xavier Del Campo Romero2023-07-201-4/+5
|
* server.c: Minor const-correctness improvementXavier Del Campo Romero2023-07-201-1/+1
|
* Fix memory leak on failed realloc(3)Xavier Del Campo Romero2023-07-201-6/+18
| | | | | | | | | | According to C99 §7.20.3.4: If memory for the new object cannot be allocated, the old object is not deallocated and its value is unchanged. Therefore, a temporary pointer must be used to ensure the original object can still be deallocated should realloc(3) return a null pointer.
* Initial commitXavier Del Campo Romero2023-07-201-0/+303