Backport from xs.

This commit is contained in:
default 2023-09-23 22:02:52 +02:00
parent 291331c745
commit 5f5e4b587e
3 changed files with 9 additions and 20 deletions

12
httpd.c
View File

@ -537,8 +537,8 @@ static void *background_thread(void *arg)
void httpd(void) void httpd(void)
/* starts the server */ /* starts the server */
{ {
char *address; const char *address;
int port; const char *port;
int rs; int rs;
pthread_t threads[MAX_THREADS] = {0}; pthread_t threads[MAX_THREADS] = {0};
int n_threads = 0; int n_threads = 0;
@ -548,10 +548,10 @@ void httpd(void)
sem_t anon_job_sem; sem_t anon_job_sem;
address = xs_dict_get(srv_config, "address"); 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) { 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; return;
} }
@ -561,7 +561,7 @@ void httpd(void)
signal(SIGTERM, term_handler); signal(SIGTERM, term_handler);
signal(SIGINT, 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 */ /* show the number of usable file descriptors */
struct rlimit r; struct rlimit r;
@ -648,5 +648,5 @@ void httpd(void)
xs *uptime = xs_str_time_diff(time(NULL) - start_time); 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));
} }

View File

@ -5,8 +5,7 @@
#define _XS_SOCKET_H #define _XS_SOCKET_H
int xs_socket_timeout(int s, double rto, double sto); 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);
int xs_socket_server(const char *addr, int port);
FILE *xs_socket_accept(int rs); FILE *xs_socket_accept(int rs);
xs_str *xs_socket_peername(int s); xs_str *xs_socket_peername(int s);
int xs_socket_connect(const char *addr, const char *serv); 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) */ /* opens a server socket by service name (or port as string) */
{ {
int rs = -1; 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) FILE *xs_socket_accept(int rs)
/* accepts an incoming connection */ /* accepts an incoming connection */
{ {

View File

@ -1 +1 @@
/* 89589de72ce632da77b0ac4b9d56d3902946b5eb */ /* b5831045cfd18e95352e5108cd47386510bf060d */