diff options
| author | 2023-09-23 22:02:52 +0200 | |
|---|---|---|
| committer | 2023-09-23 22:02:52 +0200 | |
| commit | 5f5e4b587e6d21ca43a2bbdb0969ffce441cee35 (patch) | |
| tree | 0b0c1eef8241050370b147e9b45dc615c571f9e1 | |
| parent | Backport from xs. (diff) | |
| download | penes-snac2-5f5e4b587e6d21ca43a2bbdb0969ffce441cee35.tar.gz penes-snac2-5f5e4b587e6d21ca43a2bbdb0969ffce441cee35.tar.xz penes-snac2-5f5e4b587e6d21ca43a2bbdb0969ffce441cee35.zip | |
Backport from xs.
Diffstat (limited to '')
| -rw-r--r-- | httpd.c | 12 | ||||
| -rw-r--r-- | xs_socket.h | 15 | ||||
| -rw-r--r-- | xs_version.h | 2 |
3 files changed, 9 insertions, 20 deletions
| @@ -537,8 +537,8 @@ static void *background_thread(void *arg) | |||
| 537 | void httpd(void) | 537 | void httpd(void) |
| 538 | /* starts the server */ | 538 | /* starts the server */ |
| 539 | { | 539 | { |
| 540 | char *address; | 540 | const char *address; |
| 541 | int port; | 541 | const char *port; |
| 542 | int rs; | 542 | int rs; |
| 543 | pthread_t threads[MAX_THREADS] = {0}; | 543 | pthread_t threads[MAX_THREADS] = {0}; |
| 544 | int n_threads = 0; | 544 | int n_threads = 0; |
| @@ -548,10 +548,10 @@ void httpd(void) | |||
| 548 | sem_t anon_job_sem; | 548 | sem_t anon_job_sem; |
| 549 | 549 | ||
| 550 | address = xs_dict_get(srv_config, "address"); | 550 | address = xs_dict_get(srv_config, "address"); |
| 551 | port = xs_number_get(xs_dict_get(srv_config, "port")); | 551 | port = xs_number_str(xs_dict_get(srv_config, "port")); |
| 552 | 552 | ||
| 553 | if ((rs = xs_socket_server(address, port)) == -1) { | 553 | if ((rs = xs_socket_server(address, port)) == -1) { |
| 554 | srv_log(xs_fmt("cannot bind socket to %s:%d", address, port)); | 554 | srv_log(xs_fmt("cannot bind socket to %s:%s", address, port)); |
| 555 | return; | 555 | return; |
| 556 | } | 556 | } |
| 557 | 557 | ||
| @@ -561,7 +561,7 @@ void httpd(void) | |||
| 561 | signal(SIGTERM, term_handler); | 561 | signal(SIGTERM, term_handler); |
| 562 | signal(SIGINT, term_handler); | 562 | signal(SIGINT, term_handler); |
| 563 | 563 | ||
| 564 | srv_log(xs_fmt("httpd start %s:%d %s", address, port, USER_AGENT)); | 564 | srv_log(xs_fmt("httpd start %s:%s %s", address, port, USER_AGENT)); |
| 565 | 565 | ||
| 566 | /* show the number of usable file descriptors */ | 566 | /* show the number of usable file descriptors */ |
| 567 | struct rlimit r; | 567 | struct rlimit r; |
| @@ -648,5 +648,5 @@ void httpd(void) | |||
| 648 | 648 | ||
| 649 | xs *uptime = xs_str_time_diff(time(NULL) - start_time); | 649 | xs *uptime = xs_str_time_diff(time(NULL) - start_time); |
| 650 | 650 | ||
| 651 | srv_log(xs_fmt("httpd stop %s:%d (run time: %s)", address, port, uptime)); | 651 | srv_log(xs_fmt("httpd stop %s:%s (run time: %s)", address, port, uptime)); |
| 652 | } | 652 | } |
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 @@ | |||
| 5 | #define _XS_SOCKET_H | 5 | #define _XS_SOCKET_H |
| 6 | 6 | ||
| 7 | int xs_socket_timeout(int s, double rto, double sto); | 7 | int xs_socket_timeout(int s, double rto, double sto); |
| 8 | int xs_socket_server_serv(const char *addr, const char *serv); | 8 | int xs_socket_server(const char *addr, const char *serv); |
| 9 | int xs_socket_server(const char *addr, int port); | ||
| 10 | FILE *xs_socket_accept(int rs); | 9 | FILE *xs_socket_accept(int rs); |
| 11 | xs_str *xs_socket_peername(int s); | 10 | xs_str *xs_socket_peername(int s); |
| 12 | int xs_socket_connect(const char *addr, const char *serv); | 11 | int xs_socket_connect(const char *addr, const char *serv); |
| @@ -44,7 +43,7 @@ int xs_socket_timeout(int s, double rto, double sto) | |||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | 45 | ||
| 47 | int xs_socket_server_serv(const char *addr, const char *serv) | 46 | int xs_socket_server(const char *addr, const char *serv) |
| 48 | /* opens a server socket by service name (or port as string) */ | 47 | /* opens a server socket by service name (or port as string) */ |
| 49 | { | 48 | { |
| 50 | int rs = -1; | 49 | int rs = -1; |
| @@ -88,16 +87,6 @@ end: | |||
| 88 | } | 87 | } |
| 89 | 88 | ||
| 90 | 89 | ||
| 91 | int xs_socket_server(const char *addr, int port) | ||
| 92 | /* opens a server socket (port as integer) */ | ||
| 93 | { | ||
| 94 | char serv[32]; | ||
| 95 | |||
| 96 | snprintf(serv, sizeof(serv), "%d", port); | ||
| 97 | return xs_socket_server_serv(addr, serv); | ||
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | FILE *xs_socket_accept(int rs) | 90 | FILE *xs_socket_accept(int rs) |
| 102 | /* accepts an incoming connection */ | 91 | /* accepts an incoming connection */ |
| 103 | { | 92 | { |
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 */ | ||