From a365c6da247cb141821c5f09ef7322f8e6fde693 Mon Sep 17 00:00:00 2001 From: Spiros Eliopoulos Date: Thu, 17 Oct 2019 22:37:49 -0400 Subject: [PATCH] upgrade: fix async runtime The deferred returned by the ugprade handler will dicatate when the fd will be closed. --- async/httpaf_async.ml | 7 +++---- async/httpaf_async.mli | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/async/httpaf_async.ml b/async/httpaf_async.ml index b6492b84..104c673c 100644 --- a/async/httpaf_async.ml +++ b/async/httpaf_async.ml @@ -94,11 +94,10 @@ module Server = struct type 'a t = | Ignore | Raise - | Handle of (([`Active], 'a) Socket.t -> Httpaf.Request.t -> Httpaf.Response.t -> unit) + | Handle of (([`Active], 'a) Socket.t -> Httpaf.Request.t -> Httpaf.Response.t -> unit Deferred.t) let to_handler = function - | Ignore -> (fun socket _request _response -> - don't_wait_for (Fd.close (Socket.fd socket))) + | Ignore -> (fun socket _request _response -> Fd.close (Socket.fd socket)) | Raise -> (fun socket _request _response -> don't_wait_for (Fd.close (Socket.fd socket)); @@ -160,7 +159,7 @@ module Server = struct (* Log.Global.printf "write_yield(%d)%!" (Fd.to_int_exn fd); *) Server_connection.yield_writer conn writer_thread; | `Upgrade(request, response) -> - upgrade_handler socket request response + upgrade_handler socket request response >>> Ivar.fill write_complete | `Close _ -> (* Log.Global.printf "write_close(%d)%!" (Fd.to_int_exn fd); *) Ivar.fill write_complete (); diff --git a/async/httpaf_async.mli b/async/httpaf_async.mli index 7d65219b..a4767e82 100644 --- a/async/httpaf_async.mli +++ b/async/httpaf_async.mli @@ -6,7 +6,7 @@ module Server : sig type 'a t = | Ignore | Raise - | Handle of (([`Active], 'a) Socket.t -> Request.t -> Response.t -> unit) + | Handle of (([`Active], 'a) Socket.t -> Request.t -> Response.t -> unit Deferred.t) end val create_connection_handler