Skip to content

Commit

Permalink
Add support for persistent connections in the client (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Jul 11, 2019
1 parent 372c376 commit 7c5d991
Show file tree
Hide file tree
Showing 37 changed files with 1,058 additions and 404 deletions.
15 changes: 11 additions & 4 deletions async/httpaf_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ module Server = struct
end

module Client = struct
let request ?(config=Config.default) socket request ~error_handler ~response_handler =
type t = Client_connection.t

let create_connection ?(config=Config.default) socket =
let fd = Socket.fd socket in
let writev = Faraday_async.writev_of_fd fd in
let request_body, conn =
Client_connection.request request ~error_handler ~response_handler in
let conn = Client_connection.create ~config in
let read_complete = Ivar.create () in
let buffer = Buffer.create config.read_buffer_size in
let rec reader_thread () =
Expand Down Expand Up @@ -216,5 +217,11 @@ module Client = struct
>>| fun () ->
if not (Fd.is_closed fd)
then don't_wait_for (Fd.close fd));
request_body
conn

let request = Client_connection.request

let shutdown = Client_connection.shutdown

let is_closed = Client_connection.is_closed
end
14 changes: 12 additions & 2 deletions async/httpaf_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ module Server : sig
end

module Client : sig
val request
: ?config : Config.t
type t

val create_connection
: ?config:Config.t
-> ([`Active], [< Socket.Address.t]) Socket.t
-> t

val request
: t
-> Request.t
-> error_handler : Client_connection.error_handler
-> response_handler : Client_connection.response_handler
-> [`write] Body.t

val shutdown : t -> unit

val is_closed : t -> bool
end
11 changes: 1 addition & 10 deletions esy.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@
}
}
},
"@opam/ppx_deriving": "ocaml-ppx/ppx_deriving:ppx_deriving.opam#745a45c",
"@opam/nocrypto": {
"source": "TheLortex/ocaml-nocrypto:nocrypto.opam#df2348d",
"override": {
"dependencies": {
"@opam/bigarray-compat": "*",
"@opam/ppx_sexp_conv": "*"
}
}
},
"@opam/nocrypto": "TheLortex/ocaml-nocrypto:nocrypto.opam#8e389a8",
"@opam/mirage-xen-posix": {
"source": "no-source:",
"override": {}
Expand Down
Loading

0 comments on commit 7c5d991

Please sign in to comment.