From 972c3dc5d43a114ae59386d4edfdfb8ce0f3793e Mon Sep 17 00:00:00 2001 From: default Date: Mon, 5 Aug 2024 06:01:21 +0200 Subject: Added support for listening on unix sockets. --- httpd.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 287965e..fd3d9e4 100644 --- a/httpd.c +++ b/httpd.c @@ -5,6 +5,7 @@ #include "xs_io.h" #include "xs_json.h" #include "xs_socket.h" +#include "xs_unix_socket.h" #include "xs_httpd.h" #include "xs_mime.h" #include "xs_time.h" @@ -761,8 +762,8 @@ srv_state *srv_state_op(xs_str **fname, int op) void httpd(void) /* starts the server */ { - const char *address; - const char *port; + const char *address = NULL; + const char *port = NULL; xs *full_address = NULL; int rs; pthread_t threads[MAX_THREADS] = {0}; @@ -772,11 +773,19 @@ void httpd(void) sem_t anon_job_sem; address = xs_dict_get(srv_config, "address"); - port = xs_number_str(xs_dict_get(srv_config, "port")); - full_address = xs_fmt("%s:%s", address, port); + if (*address == '/') { + rs = xs_unix_socket_server(address, NULL); + full_address = xs_fmt("unix:%s", address); + } + else { + port = xs_number_str(xs_dict_get(srv_config, "port")); + full_address = xs_fmt("%s:%s", address, port); + + rs = xs_socket_server(address, port); + } - if ((rs = xs_socket_server(address, port)) == -1) { + if (rs == -1) { srv_log(xs_fmt("cannot bind socket to %s", full_address)); return; } -- cgit v1.2.3