summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-08-05 06:01:21 +0200
committerdefault <nobody@localhost>2024-08-05 06:01:21 +0200
commit972c3dc5d43a114ae59386d4edfdfb8ce0f3793e (patch)
tree2568b6190dc0ca34478ccabc1191e504d1e8cfcf /httpd.c
parente9b108a6e0f09d74ee605f1a854ecbdc12a65c92 (diff)
Added support for listening on unix sockets.
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c19
1 files changed, 14 insertions, 5 deletions
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;
}