From 5f5e4b587e6d21ca43a2bbdb0969ffce441cee35 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 23 Sep 2023 22:02:52 +0200 Subject: [PATCH] Backport from xs. --- httpd.c | 12 ++++++------ xs_socket.h | 15 ++------------- xs_version.h | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/httpd.c b/httpd.c index 52684cf..e2cfbb0 100644 --- a/httpd.c +++ b/httpd.c @@ -537,8 +537,8 @@ static void *background_thread(void *arg) void httpd(void) /* starts the server */ { - char *address; - int port; + const char *address; + const char *port; int rs; pthread_t threads[MAX_THREADS] = {0}; int n_threads = 0; @@ -548,10 +548,10 @@ void httpd(void) sem_t anon_job_sem; address = xs_dict_get(srv_config, "address"); - port = xs_number_get(xs_dict_get(srv_config, "port")); + port = xs_number_str(xs_dict_get(srv_config, "port")); if ((rs = xs_socket_server(address, port)) == -1) { - srv_log(xs_fmt("cannot bind socket to %s:%d", address, port)); + srv_log(xs_fmt("cannot bind socket to %s:%s", address, port)); return; } @@ -561,7 +561,7 @@ void httpd(void) signal(SIGTERM, term_handler); signal(SIGINT, term_handler); - srv_log(xs_fmt("httpd start %s:%d %s", address, port, USER_AGENT)); + srv_log(xs_fmt("httpd start %s:%s %s", address, port, USER_AGENT)); /* show the number of usable file descriptors */ struct rlimit r; @@ -648,5 +648,5 @@ void httpd(void) xs *uptime = xs_str_time_diff(time(NULL) - start_time); - srv_log(xs_fmt("httpd stop %s:%d (run time: %s)", address, port, uptime)); + srv_log(xs_fmt("httpd stop %s:%s (run time: %s)", address, port, uptime)); } diff --git a/xs_socket.h b/xs_socket.h index a2f9cb6..eea2f2d 100644 --- a/xs_socket.h +++ b/xs_socket.h @@ -5,8 +5,7 @@ #define _XS_SOCKET_H int xs_socket_timeout(int s, double rto, double sto); -int xs_socket_server_serv(const char *addr, const char *serv); -int xs_socket_server(const char *addr, int port); +int xs_socket_server(const char *addr, const char *serv); FILE *xs_socket_accept(int rs); xs_str *xs_socket_peername(int s); int xs_socket_connect(const char *addr, const char *serv); @@ -44,7 +43,7 @@ int xs_socket_timeout(int s, double rto, double sto) } -int xs_socket_server_serv(const char *addr, const char *serv) +int xs_socket_server(const char *addr, const char *serv) /* opens a server socket by service name (or port as string) */ { int rs = -1; @@ -88,16 +87,6 @@ end: } -int xs_socket_server(const char *addr, int port) -/* opens a server socket (port as integer) */ -{ - char serv[32]; - - snprintf(serv, sizeof(serv), "%d", port); - return xs_socket_server_serv(addr, serv); -} - - FILE *xs_socket_accept(int rs) /* accepts an incoming connection */ { diff --git a/xs_version.h b/xs_version.h index 752e1be..d0c2fb5 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 89589de72ce632da77b0ac4b9d56d3902946b5eb */ +/* b5831045cfd18e95352e5108cd47386510bf060d */