http-server.c

Basic HTTP server and router in C
git clone git://git.finwo.net/lib/http-server.c
Log | Files | Refs | README

commit 3f0f44259aaa23c5600af2bfdb86b651111ae055
parent 48b10a0c6ec401a0bbfbe2b539ca7355a5f159b4
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Sun,  6 Aug 2023 00:12:01 +0200

Throw error when listening fails

Diffstat:
Msrc/http-server.c | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/http-server.c b/src/http-server.c @@ -116,12 +116,12 @@ void http_server_route(const char *method, const char *path, void (*fn)(struct h void http_server_main(const struct http_server_opts *opts) { struct fnet_udata *ludata = calloc(1, sizeof(struct fnet_udata)); - ludata->addr = opts->addr, - ludata->port = opts->port, - ludata->cudata = opts->udata, - ludata->evs = opts->evs, + ludata->addr = opts->addr; + ludata->port = opts->port; + ludata->cudata = opts->udata; + ludata->evs = opts->evs; - fnet_listen(opts->addr, opts->port, &((struct fnet_options_t){ + if (fnet_listen(opts->addr, opts->port, &((struct fnet_options_t){ .proto = FNET_PROTO_TCP, .flags = 0, .onListen = _hs_onServing, @@ -130,7 +130,9 @@ void http_server_main(const struct http_server_opts *opts) { .onTick = NULL, .onClose = NULL, .udata = ludata, - })); + }))) { + exit(1); + } // This is a forever function fnet_main();