diff options
| -rw-r--r-- | src/server.ml | 4 | ||||
| -rw-r--r-- | src/server.mli | 2 | ||||
| -rw-r--r-- | src/ucs.ml | 12 | 
3 files changed, 14 insertions, 4 deletions
| diff --git a/src/server.ml b/src/server.ml index 2c1c4b9..d3cf00e 100644 --- a/src/server.ml +++ b/src/server.ml @@ -47,7 +47,7 @@ let respond ?(mime="text/html; charset=utf-8") ?(status=`OK) body =    let headers = Header.init_with "Content-Type" mime in    Server.respond_string ~status ~body ~headers () -let serve base_url celcat_url mode = +let serve base_url celcat_url mode stop =    let fetch = fetch celcat_url in    let callback _conn req _body =      let meth = Request.meth req and @@ -75,4 +75,4 @@ let serve base_url celcat_url mode =      | _ ->         Server.respond_string           ~status:`Method_not_allowed ~body:"Method not allowed\n" () in -  Server.create ~mode (Server.make ~callback ()) +  Server.create ~stop ~mode (Server.make ~callback ()) diff --git a/src/server.mli b/src/server.mli index af3f0e8..cf3bac2 100644 --- a/src/server.mli +++ b/src/server.mli @@ -15,4 +15,4 @@   *    along with ucs.  If not, see <http://www.gnu.org/licenses/>.   *) -val serve : string -> Uri.t -> Conduit_lwt_unix.server -> unit Lwt.t +val serve : string -> Uri.t -> Conduit_lwt_unix.server -> unit Lwt.t -> unit Lwt.t @@ -49,7 +49,17 @@ let () =          mode = match socket with        | Some s -> `Unix_domain_socket (`File s)        | None -> `TCP (`Port port) in -    Lwt_main.run (Server.serve base_url celcat_uri mode) in +    let stop, r = Lwt.wait () in +    Lwt_unix.on_signal Sys.sigint +      (fun _ -> Lwt.wakeup r ()) |> ignore; +    Lwt_unix.on_signal Sys.sigterm +      (fun _ -> Lwt.wakeup r ()) |> ignore; +    Lwt_main.run ( +      Lwt.finalize +        (fun () -> Server.serve base_url celcat_uri mode stop) +        (fun () -> match socket with +           | Some s -> Lwt_unix.unlink s +           | None -> Lwt.return_unit)) in    let cmd =      let doc = "micro celcatsanitizer: convert celcat \                 calendar to ICS files, on the fly." and | 
