From cf62e96abb1514cdf701350a3263bc874b0027f8 Mon Sep 17 00:00:00 2001 From: Spiros Eliopoulos Date: Thu, 17 Oct 2019 22:35:25 -0400 Subject: [PATCH] upgrade: fix lwt runtime The future returned by the ugprade handler will dicatate when the fd will be closed. --- lwt-unix/httpaf_lwt_unix.ml | 7 +++---- lwt-unix/httpaf_lwt_unix.mli | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lwt-unix/httpaf_lwt_unix.ml b/lwt-unix/httpaf_lwt_unix.ml index cd11cffd..30ff18c4 100644 --- a/lwt-unix/httpaf_lwt_unix.ml +++ b/lwt-unix/httpaf_lwt_unix.ml @@ -109,10 +109,10 @@ module Server = struct type t = | Ignore | Raise - | Handle of (Lwt_unix.file_descr -> Httpaf.Request.t -> Httpaf.Response.t -> unit) + | Handle of (Lwt_unix.file_descr -> Httpaf.Request.t -> Httpaf.Response.t -> unit Lwt.t) let to_handler = function - | Ignore -> (fun socket _request _response -> Lwt.async (fun () -> Lwt_unix.close socket)) + | Ignore -> (fun socket _request _response -> Lwt_unix.close socket) | Raise -> (fun socket _request _response -> Lwt.async (fun () -> Lwt_unix.close socket); @@ -188,8 +188,7 @@ module Server = struct Server_connection.report_write_result connection result; write_loop_step () | `Upgrade(request, response) -> - upgrade_handler socket request response; - Lwt.return_unit + upgrade_handler socket request response | `Yield -> Server_connection.yield_writer connection write_loop; Lwt.return_unit diff --git a/lwt-unix/httpaf_lwt_unix.mli b/lwt-unix/httpaf_lwt_unix.mli index c92e061a..24d5f7b7 100644 --- a/lwt-unix/httpaf_lwt_unix.mli +++ b/lwt-unix/httpaf_lwt_unix.mli @@ -43,7 +43,7 @@ module Server : sig type t = | Ignore | Raise - | Handle of (Lwt_unix.file_descr -> Httpaf.Request.t -> Httpaf.Response.t -> unit) + | Handle of (Lwt_unix.file_descr -> Httpaf.Request.t -> Httpaf.Response.t -> unit Lwt.t) end val create_connection_handler