Skip to content

Commit

Permalink
upgrade: fix async runtime
Browse files Browse the repository at this point in the history
The deferred returned by the ugprade handler will dicatate when the fd
will be closed.
  • Loading branch information
seliopou committed Oct 18, 2019
1 parent cf62e96 commit 139bf68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions async/httpaf_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion async/httpaf_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 139bf68

Please sign in to comment.