diff options
| author | 2024-08-05 06:01:21 +0200 | |
|---|---|---|
| committer | 2024-08-05 06:01:21 +0200 | |
| commit | 972c3dc5d43a114ae59386d4edfdfb8ce0f3793e (patch) | |
| tree | 2568b6190dc0ca34478ccabc1191e504d1e8cfcf /httpd.c | |
| parent | Minor logging tweaks. (diff) | |
| download | snac2-972c3dc5d43a114ae59386d4edfdfb8ce0f3793e.tar.gz snac2-972c3dc5d43a114ae59386d4edfdfb8ce0f3793e.tar.xz snac2-972c3dc5d43a114ae59386d4edfdfb8ce0f3793e.zip | |
Added support for listening on unix sockets.
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 19 |
1 files changed, 14 insertions, 5 deletions
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "xs_io.h" | 5 | #include "xs_io.h" |
| 6 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 7 | #include "xs_socket.h" | 7 | #include "xs_socket.h" |
| 8 | #include "xs_unix_socket.h" | ||
| 8 | #include "xs_httpd.h" | 9 | #include "xs_httpd.h" |
| 9 | #include "xs_mime.h" | 10 | #include "xs_mime.h" |
| 10 | #include "xs_time.h" | 11 | #include "xs_time.h" |
| @@ -761,8 +762,8 @@ srv_state *srv_state_op(xs_str **fname, int op) | |||
| 761 | void httpd(void) | 762 | void httpd(void) |
| 762 | /* starts the server */ | 763 | /* starts the server */ |
| 763 | { | 764 | { |
| 764 | const char *address; | 765 | const char *address = NULL; |
| 765 | const char *port; | 766 | const char *port = NULL; |
| 766 | xs *full_address = NULL; | 767 | xs *full_address = NULL; |
| 767 | int rs; | 768 | int rs; |
| 768 | pthread_t threads[MAX_THREADS] = {0}; | 769 | pthread_t threads[MAX_THREADS] = {0}; |
| @@ -772,11 +773,19 @@ void httpd(void) | |||
| 772 | sem_t anon_job_sem; | 773 | sem_t anon_job_sem; |
| 773 | 774 | ||
| 774 | address = xs_dict_get(srv_config, "address"); | 775 | address = xs_dict_get(srv_config, "address"); |
| 775 | port = xs_number_str(xs_dict_get(srv_config, "port")); | ||
| 776 | 776 | ||
| 777 | full_address = xs_fmt("%s:%s", address, port); | 777 | if (*address == '/') { |
| 778 | rs = xs_unix_socket_server(address, NULL); | ||
| 779 | full_address = xs_fmt("unix:%s", address); | ||
| 780 | } | ||
| 781 | else { | ||
| 782 | port = xs_number_str(xs_dict_get(srv_config, "port")); | ||
| 783 | full_address = xs_fmt("%s:%s", address, port); | ||
| 784 | |||
| 785 | rs = xs_socket_server(address, port); | ||
| 786 | } | ||
| 778 | 787 | ||
| 779 | if ((rs = xs_socket_server(address, port)) == -1) { | 788 | if (rs == -1) { |
| 780 | srv_log(xs_fmt("cannot bind socket to %s", full_address)); | 789 | srv_log(xs_fmt("cannot bind socket to %s", full_address)); |
| 781 | return; | 790 | return; |
| 782 | } | 791 | } |