From 98f5f52461b0c1ab1ee3331722bd32e2db9e1d41 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Date: Thu, 16 Nov 2023 12:23:08 +0100 Subject: Split handler_loop from handler_listen 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. --- include/libweb/handler.h | 4 +++- include/libweb/server.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/libweb/handler.h b/include/libweb/handler.h index f7bc76a..493e24c 100644 --- a/include/libweb/handler.h +++ b/include/libweb/handler.h @@ -20,6 +20,8 @@ struct handler *handler_alloc(const struct handler_cfg *cfg); void handler_free(struct handler *h); int handler_add(struct handler *h, const char *url, enum http_op op, handler_fn f, void *user); -int handler_listen(struct handler *h, unsigned short port); +int handler_listen(struct handler *h, unsigned short port, + unsigned short *outport); +int handler_loop(struct handler *h); #endif /* HANDLER_H */ diff --git a/include/libweb/server.h b/include/libweb/server.h index 74f06ae..b3691aa 100644 --- a/include/libweb/server.h +++ b/include/libweb/server.h @@ -4,7 +4,7 @@ #include #include -struct server *server_init(unsigned short port); +struct server *server_init(unsigned short port, unsigned short *outport); struct server_client *server_poll(struct server *s, bool *io, bool *exit); int server_read(void *buf, size_t n, struct server_client *c); int server_write(const void *buf, size_t n, struct server_client *c); -- cgit v1.2.3