Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for persistent connections in the client #5

Merged
merged 15 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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