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

Adapt to EIO v0.12 #184

Merged
merged 2 commits into from
Aug 30, 2023
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
2 changes: 1 addition & 1 deletion bin/carl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ let inflate response_body =
let handle_response
~cli
~sw
~(stdout : Eio_unix.sink)
~(stdout : _ Eio_unix.sink)
({ Response.body; _ } as response)
=
let open Util.Result.Syntax in
Expand Down
21 changes: 11 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
inputs.nix-filter.url = "github:numtide/nix-filter";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs = {
url = "github:nix-ocaml/nix-overlays";
url = "github:nix-ocaml/nix-overlays/anmonteiro/eio-0.12";
inputs.flake-utils.follows = "flake-utils";
};

Expand Down
8 changes: 5 additions & 3 deletions lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ let create_http_connection ~sw ~config ~conn_info ~uri fd =

let create_https_connection ~sw ~config ~conn_info ~uri fd =
let { Connection_info.host; _ } = conn_info in
let*! ssl_client = Openssl.connect ~config ~hostname:host fd in
let ssl_socket = Eio_ssl.ssl_socket ssl_client in
let*! { ssl = ssl_client; ssl_ctx } =
Openssl.connect ~config ~hostname:host fd
in
let ssl_socket = Eio_ssl.Context.ssl_socket ssl_ctx in
let (module Https), version =
match Ssl.get_negotiated_alpn_protocol ssl_socket with
| None ->
Expand Down Expand Up @@ -143,7 +145,7 @@ let open_connection ~sw ~config ~uri env conn_info =
| `HTTPS -> create_https_connection ~sw ~config ~conn_info ~uri socket

(* This function takes a `conn_info` and a `Connection.t` instead of just a `t`
* too allow reuse when shutting down old connection.
* too allow reuse when shutting down an old connection.
*
* Due to the fact that `t.conn` is mutable, we could run into weird
* asynchronous edge cases and shut down the connection that's currently in use
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type t =
| Conn :
{ impl : (module Http_intf.HTTPCommon with type Client.t = 'a)
; connection : 'a
; fd : < Eio.Net.stream_socket ; Eio.Flow.close >
; fd : Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
; mutable info : Info.t
; mutable uri : Uri.t
(* The connection URI. Request entrypoints connect here. Mutable so
Expand Down
6 changes: 3 additions & 3 deletions lib/http2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ module MakeHTTP2 (Runtime_scheme : Scheme.Runtime.SCHEME) : sig
and type scheme = Runtime_scheme.t

val make_error_handler :
fd:#Eio.Flow.two_way
fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Server_intf.error_handler
-> Eio.Net.Sockaddr.stream
-> H2.Server_connection.error_handler

val make_request_handler :
sw:Switch.t
-> config:Server_config.t
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Request_info.t Server_intf.Handler.t
-> Eio.Net.Sockaddr.stream
-> H2.Reqd.t
Expand Down Expand Up @@ -296,7 +296,7 @@ module HTTP : Http_intf.HTTP2 with type scheme = Scheme.http = struct
let create_h2c_connection_handler :
config:Server_config.t
-> sw:Eio.Switch.t
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> error_handler:Server_intf.error_handler
-> http_request:Httpaf.Request.t
-> request_body:Bigstringaf.t IOVec.t list
Expand Down
4 changes: 2 additions & 2 deletions lib/http_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ let create_h2c_connection
let shutdown :
type t.
(module Http_intf.HTTPCommon with type Client.t = t)
-> fd:#Eio.Net.stream_socket
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> t
-> unit
=
fun (module Http) ~fd conn ->
Promise.await (Http.Client.shutdown conn);
Eio.Flow.close fd
Eio.Net.close fd

let is_closed :
type t. (module Http_intf.HTTPCommon with type Client.t = t) -> t -> bool
Expand Down
4 changes: 2 additions & 2 deletions lib/http_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module type Client = sig
config:Config.t
-> error_handler:error_handler
-> sw:Eio.Switch.t
-> #Eio.Flow.two_way
-> Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> t * Gluten_eio.Client.t

val request :
Expand Down Expand Up @@ -149,7 +149,7 @@ module type HTTP2 = sig
val create_h2c_connection_handler :
config:Server_config.t
-> sw:Eio.Switch.t
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> error_handler:Server_intf.error_handler
-> http_request:Httpaf.Request.t
-> request_body:Bigstringaf.t IOVec.t list
Expand Down
8 changes: 4 additions & 4 deletions lib/http_server_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type t =
| Descriptor :
{ impl : (module Http_intf.HTTPServerCommon with type Reqd.t = 'reqd)
; reqd : 'reqd
; handle : #Eio.Flow.two_way
; handle : Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
; scheme : Scheme.t
(* ; connection_error_received : Error.server Promise.t *)
; version : Versions.HTTP.t
Expand All @@ -75,7 +75,7 @@ let create_descriptor :
?upgrade:upgrade
-> (module Http_intf.HTTPServerCommon with type Reqd.t = reqd)
-> config:Server_config.t
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> scheme:Scheme.t
-> version:Versions.HTTP.t
-> handler:Request_info.t Server_intf.Handler.t
Expand Down Expand Up @@ -108,7 +108,7 @@ let do_sendfile :
type writer.
(module Http_intf.HTTPServerCommon with type Body.Writer.t = writer)
-> src_fd:Unix.file_descr
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> report_exn:(exn -> unit)
-> writer
-> unit
Expand Down Expand Up @@ -244,7 +244,7 @@ let handle_error :
-> start_response:(Headers.t -> writer)
-> error_handler:Server_intf.error_handler
-> scheme:Scheme.t
-> fd:#Eio.Flow.two_way
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Eio.Net.Sockaddr.stream
-> Error.server
-> unit
Expand Down
13 changes: 9 additions & 4 deletions lib/openssl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ let setup_client_ctx
Ssl.set_host ssl_sock hostname);
Ok ssl_ctx

type t =
{ ssl : Eio_ssl.t
; ssl_ctx : Eio_ssl.Context.t
}

(* Assumes that the file descriptor is connected. *)
let connect ~hostname ~config fd =
let ({ Config.allow_insecure; min_tls_version; max_tls_version; _ } as
Expand Down Expand Up @@ -359,7 +364,7 @@ let connect ~hostname ~config fd =
(Ssl.get_cipher_name ssl_cipher));
(* Verification succeeded, or `allow_insecure` is true *)
log_cert_info ~allow_insecure ssl_sock;
Ok ssl
Ok { ssl; ssl_ctx }
| Error e ->
let verify_result = Ssl.get_verify_result ssl_sock in
if verify_result <> 0
Expand Down Expand Up @@ -440,8 +445,8 @@ let setup_server_ctx
ctx

(* assumes an `accept`ed socket *)
let get_negotiated_alpn_protocol ssl_server =
let ssl_socket = Eio_ssl.ssl_socket ssl_server in
let get_negotiated_alpn_protocol ssl_ctx =
let ssl_socket = Eio_ssl.Context.ssl_socket ssl_ctx in
match Ssl.get_negotiated_alpn_protocol ssl_socket with
| Some "http/1.1" -> Versions.HTTP.HTTP_1_1
| Some "h2" -> HTTP_2
Expand Down Expand Up @@ -471,7 +476,7 @@ let accept
Eio.Time.with_timeout clock timeout (fun () -> Ok (Eio_ssl.accept ssl_ctx))
with
| Ok ssl_server ->
let alpn_version = get_negotiated_alpn_protocol ssl_server in
let alpn_version = get_negotiated_alpn_protocol ssl_ctx in
Ok { socket = ssl_server; alpn_version }
| Error `Timeout ->
Result.error
Expand Down
5 changes: 4 additions & 1 deletion lib/piaf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,10 @@ module Server : sig

module Command : sig
type connection_handler =
sw:Eio.Switch.t -> Eio.Flow.two_way -> Eio.Net.Sockaddr.stream -> unit
sw:Eio.Switch.t
-> Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Eio.Net.Sockaddr.stream
-> unit

type server := t
type t
Expand Down
15 changes: 10 additions & 5 deletions lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ let https_connection_handler ~https ~clock t : connection_handler =
~error_handler
~request_handler:handler
~sw
(ssl_server :> Eio.Flow.two_way)
ssl_server
client_address

module Command = struct
Expand All @@ -177,10 +177,15 @@ module Command = struct
type connection_handler = Server_intf.connection_handler

type nonrec t =
{ sockets : Eio.Net.listening_socket list
{ sockets :
Eio_unix.Net.listening_socket_ty Eio_unix.Net.listening_socket list
; shutdown_resolvers : (unit -> unit) list
; client_sockets : (int, Eio.Net.stream_socket) Hashtbl.t list
; clock : Eio.Time.clock
; client_sockets :
( int
, Eio_unix.Net.stream_socket_ty Eio_unix.Net.stream_socket )
Hashtbl.t
list
; clock : float Eio.Time.clock_ty r
; shutdown_timeout : float
}

Expand Down Expand Up @@ -246,7 +251,7 @@ module Command = struct
Hashtbl.replace client_sockets connection_id socket;
Switch.on_release sw (fun () ->
Hashtbl.remove client_sockets connection_id);
connection_handler ~sw (socket :> Eio.Flow.two_way) addr)))
connection_handler ~sw socket addr)))
done);
fun () -> Promise.resolve released_u ()

Expand Down
5 changes: 4 additions & 1 deletion lib/server_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ module Error_response = struct
end

type connection_handler =
sw:Switch.t -> Eio.Flow.two_way -> Eio.Net.Sockaddr.stream -> unit
sw:Switch.t
-> Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Eio.Net.Sockaddr.stream
-> unit

type error_handler =
Eio.Net.Sockaddr.stream
Expand Down
2 changes: 1 addition & 1 deletion lib_test/helper_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module ALPN = struct
try
let ssl_ctx = Eio_ssl.Context.create ~ctx:server_ctx fd in
let ssl_server = Eio_ssl.accept ssl_ctx in
let ssl_socket = Eio_ssl.ssl_socket ssl_server in
let ssl_socket = Eio_ssl.Context.ssl_socket ssl_ctx in
match Ssl.get_negotiated_alpn_protocol ssl_socket with
| Some "http/1.1" -> http1s_handler ~sw client_addr ssl_server
| Some "h2" -> h2s_handler ~sw client_addr ssl_server
Expand Down
5 changes: 1 addition & 4 deletions lib_test/test_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,7 @@ let test_default_headers ~sw env () =
let test_case :
string
-> Alcotest.speed_level
-> (sw:Switch.t
-> < clock : #Eio.Time.clock ; net : #Eio.Net.t ; .. >
-> unit
-> unit)
-> (sw:Switch.t -> Eio_unix.Stdenv.base -> unit -> unit)
-> string * Alcotest.speed_level * (unit -> unit)
=
fun desc ty f ->
Expand Down
2 changes: 1 addition & 1 deletion multipart_test/multipart_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ let test_no_boundary_but_boundary_expected ~sw:_ _env () =
let test_case
: string -> Alcotest.speed_level
-> (sw:Switch.t
-> < clock : #Eio.Time.clock ; net : #Eio.Net.t ; .. >
-> Eio_unix.Stdenv.base
-> unit
-> unit)
-> string * Alcotest.speed_level * (unit -> unit)
Expand Down
3 changes: 0 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ rec {
];
};

useDune2 = true;

nativeBuildInputs = with ocamlPackages; [ ocaml dune findlib ];
propagatedBuildInputs = with ocamlPackages; [
logs
eio-ssl
Expand Down
Loading