diff --git a/lib/client.ml b/lib/client.ml index 75d6197..dec66cd 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -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 } @@ -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 = diff --git a/lib/connection.ml b/lib/connection.ml index ae7b8ac..db27c02 100644 --- a/lib/connection.ml +++ b/lib/connection.ml @@ -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 diff --git a/lib/piaf.mli b/lib/piaf.mli index dd5acdc..578a764 100644 --- a/lib/piaf.mli +++ b/lib/piaf.mli @@ -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 @@ -694,7 +700,7 @@ 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 @@ -702,7 +708,7 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 = @@ -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 : @@ -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 diff --git a/lib/server.ml b/lib/server.ml index 8409185..ea50f95 100644 --- a/lib/server.ml +++ b/lib/server.ml @@ -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 @@ -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 : @@ -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 } @@ -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 } @@ -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