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. --- server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 8cea044..d460155 100644 --- a/server.c +++ b/server.c @@ -320,7 +320,8 @@ static int init_signals(void) return 0; } -struct server *server_init(const unsigned short port) +struct server *server_init(const unsigned short port, + unsigned short *const outport) { struct server *const s = malloc(sizeof *s); @@ -373,8 +374,9 @@ struct server *server_init(const unsigned short port) fprintf(stderr, "%s: getsockname(2): %s\n", __func__, strerror(errno)); goto failure; } + else if (outport) + *outport = ntohs(in.sin_port); - printf("Listening on port %hu\n", ntohs(in.sin_port)); return s; failure: -- cgit v1.2.3