Skip to content

Commit 0fd77bb

Browse files
committed
httpev: add setup_bind_lwt function
setup http_server with http_config binded to systemd socket (by default) or to provided addr (host:port)
1 parent 6c1b06d commit 0fd77bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

httpev.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,20 @@ let setup_lwt config answer =
11191119
let server_lwt config answer =
11201120
Lwt_main.run @@ setup_lwt config answer
11211121

1122+
let setup_bind_lwt addr http_config =
1123+
match addr, Systemd.Daemon.listen_fds_lwt () with
1124+
| None, [] ->
1125+
Exn.fail "bind not provided and no systemd socket available"
1126+
| None, fd :: fds ->
1127+
log#info "starting httpev in systemd mode";
1128+
if fds <> [] then
1129+
log#warn "more than one fd is provided by systemd, only the first one is used and the other ones are ignored";
1130+
setup_fd_lwt fd http_config, "systemd socket"
1131+
| Some bind, _ ->
1132+
let connection = Nix.sockaddr_of_string bind in
1133+
let signature = sprintf "listen %s" (Nix.show_addr connection) in
1134+
setup_lwt { http_config with connection }, signature
1135+
11221136
module Answer = struct
11231137

11241138
let return ?(status=`Ok) ?(extra=[]) ~typ data : [> `Body of reply_status reply' ] Lwt.t =

0 commit comments

Comments
 (0)