Skip to content

Commit

Permalink
httpev: add setup_bind_lwt function
Browse files Browse the repository at this point in the history
setup http_server with http_config binded to systemd socket (by default)
or to provided addr (host:port)
  • Loading branch information
level-a committed Nov 5, 2020
1 parent 6c1b06d commit 4703287
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions httpev.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ let default =

include Httpev_common

type http_server_bind =
| Systemd of Lwt_unix.file_descr
| Connection of Unix.sockaddr

type partial_body = {
line1 : string;
content_length : int option;
Expand Down Expand Up @@ -1119,6 +1123,24 @@ let setup_lwt config answer =
let server_lwt config answer =
Lwt_main.run @@ setup_lwt config answer

let setup_bind_lwt addr config answer =
let connection =
match addr, Systemd.Daemon.listen_fds_lwt () with
| None, [] -> Exn.fail "bind not provided and no systemd socket available"
| None, fd :: fds ->
if fds <> [] then
log#warn "more than one fd is provided by systemd, only the first one is used and the other ones are ignored";
Systemd fd
| Some addr, _ -> Connection addr
in
match connection with
| Systemd fd ->
log#info "starting httpev in systemd mode";
setup_fd_lwt fd config answer
| Connection connection ->
log#info "starting httpev on %s" (Nix.show_addr connection);
setup_lwt { config with connection } answer

module Answer = struct

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

0 comments on commit 4703287

Please sign in to comment.