Skip to content
Open
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: 13 additions & 2 deletions lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ open Import
module Logs = (val Logging.setup ~src:"piaf.client" ~doc:"Piaf Client module")
module Connection_info = Connection.Info

type 'a env = 'a constraint 'a =
< clock : _ Eio.Time.clock
; net : [> [ `Generic | `Unix ] Eio.Net.ty ] Eio.Net.t
; ..
> as 'a

type required_env =
< clock : float Eio.Time.clock_ty Eio.Std.r
; net : Eio_unix.Net.t
> env

type t =
{ mutable conn : Connection.t
; env : Eio_unix.Stdenv.base
; env : required_env
; sw : Switch.t
}

Expand Down Expand Up @@ -437,7 +448,7 @@ let rec send_request_and_handle_response
let create ?(config = Config.default) ~sw env uri =
let*! conn_info = Connection_info.of_uri env ~config uri in
match open_connection ~config ~sw ~uri:conn_info.uri env conn_info with
| Ok conn -> Ok { conn; env; sw }
| Ok conn -> Ok { conn; env :> required_env; sw }
| Error (#Error.client as err) -> Error err

let call t ~meth ?(headers = []) ?(body = Body.empty) target =
Expand Down
5 changes: 3 additions & 2 deletions lib/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ module Version = Httpun.Version
module Logs =
(val Logging.setup ~src:"piaf.connection" ~doc:"Piaf Connection module")

let order_v4v6 = Eio.Net.Ipaddr.fold ~v4:(fun _ -> -1) ~v6:(fun _ -> 1)

let resolve_host =
let order_v4v6 = Eio.Net.Ipaddr.fold ~v4:(fun _ -> -1) ~v6:(fun _ -> 1) in
fun (env : Eio_unix.Stdenv.base) ~config ~port hostname ->
fun env ~config ~port hostname ->
let clock = Eio.Stdenv.clock env in
let network = Eio.Stdenv.net env in
match
Expand Down
33 changes: 23 additions & 10 deletions lib/piaf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,18 @@ end
once the request is done. Useful for isolated requests. *)

module Client : sig
type 'a env = 'a constraint 'a =
< clock : _ Eio.Time.clock
; net : [> [ `Generic | `Unix ] Eio.Net.ty ] Eio.Net.t
; ..
> as 'a

type t

val create :
?config:Config.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (t, [> Error.client ]) result
(** [create ?config uri] opens a connection to [uri] (initially) that can be
Expand Down Expand Up @@ -694,15 +700,15 @@ module Client : sig
?config:Config.t
-> ?headers:(string * string) list
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

val get :
?config:Config.t
-> ?headers:(string * string) list
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

Expand All @@ -711,7 +717,7 @@ module Client : sig
-> ?headers:(string * string) list
-> ?body:Body.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

Expand All @@ -720,7 +726,7 @@ module Client : sig
-> ?headers:(string * string) list
-> ?body:Body.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

Expand All @@ -729,7 +735,7 @@ module Client : sig
-> ?headers:(string * string) list
-> ?body:Body.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

Expand All @@ -738,7 +744,7 @@ module Client : sig
-> ?headers:(string * string) list
-> ?body:Body.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> Uri.t
-> (Response.t, [> Error.t ]) result

Expand All @@ -747,7 +753,7 @@ module Client : sig
-> ?headers:(string * string) list
-> ?body:Body.t
-> sw:Eio.Switch.t
-> Eio_unix.Stdenv.base
-> _ env
-> meth:Method.t
-> Uri.t
-> (Response.t, [> Error.t ]) result
Expand All @@ -765,6 +771,13 @@ module Request_info : sig
end

module Server : sig
type 'a env = 'a constraint 'a =
< clock : _ Eio.Time.clock
; domain_mgr : _ Eio.Domain_manager.t
; net : [> [ `Generic | `Unix ] Eio.Net.ty ] Eio.Net.t
; ..
> as 'a

module Config : sig
module HTTPS : sig
type t =
Expand Down Expand Up @@ -905,7 +918,7 @@ module Server : sig
type server := t
type t

val start : sw:Eio.Switch.t -> Eio_unix.Stdenv.base -> server -> t
val start : sw:Eio.Switch.t -> _ env -> server -> t
val shutdown : t -> unit

val listen :
Expand All @@ -916,7 +929,7 @@ module Server : sig
-> reuse_port:bool
-> domains:int
-> shutdown_timeout:float
-> Eio_unix.Stdenv.base
-> _ env
-> connection_handler
-> t
(** [listen ~sw ?bind_to_address ~network ~port connection_handler] starts a
Expand Down
15 changes: 12 additions & 3 deletions lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ module Reqd = Httpun.Reqd
module Server_connection = Httpun.Server_connection
module Config = Server_config

type 'a env = 'a constraint 'a =
< clock : _ Eio.Time.clock
; domain_mgr : _ Eio.Domain_manager.t
; net : [> [ `Generic | `Unix ] Eio.Net.ty ] Eio.Net.t
; ..
> as 'a

type 'ctx ctx = 'ctx Handler.ctx =
{ ctx : 'ctx
; request : Request.t
Expand Down Expand Up @@ -181,6 +188,8 @@ module Command = struct
let empty = Fun.id, Hashtbl.create 0
end

type clock = float Eio.Time.clock_ty Eio.Time.clock

type nonrec t =
{ (* types like [_ array] mean per domain * listening address *)
sockets :
Expand All @@ -191,7 +200,7 @@ module Command = struct
, Eio_unix.Net.stream_socket_ty Eio_unix.Net.stream_socket )
Hashtbl.t
array
; clock : float Eio.Time.clock_ty r
; clock : clock
; shutdown_timeout : float
}

Expand Down Expand Up @@ -322,7 +331,7 @@ module Command = struct
{ sockets = [ listening_socket ]
; shutdown_resolvers = Array.map fst resolvers
; client_sockets = Array.map snd resolvers
; clock = Eio.Stdenv.clock env
; clock = (Eio.Stdenv.clock env :> clock)
; shutdown_timeout
}

Expand Down Expand Up @@ -368,7 +377,7 @@ module Command = struct
https_command.shutdown_resolvers
; client_sockets =
Array.append command.client_sockets https_command.client_sockets
; clock
; clock = (clock :> clock)
; shutdown_timeout = config.shutdown_timeout
}
end
Loading