From 3886b3187023fbbda989239f6055ffa2d61afa29 Mon Sep 17 00:00:00 2001 From: Tim McGilchrist Date: Mon, 6 Nov 2023 08:03:38 +1100 Subject: [PATCH] Update example code for Eio. --- examples/greeter-client-eio/greeter_client_eio.ml | 3 +-- examples/greeter-server-eio/greeter_server_eio.ml | 3 +-- examples/routeguide-tutorial.md | 7 +++---- examples/routeguide/src/client.ml | 3 +-- examples/routeguide/src/server.ml | 9 ++++----- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/greeter-client-eio/greeter_client_eio.ml b/examples/greeter-client-eio/greeter_client_eio.ml index 0fc535b..c8b0530 100644 --- a/examples/greeter-client-eio/greeter_client_eio.ml +++ b/examples/greeter-client-eio/greeter_client_eio.ml @@ -16,8 +16,7 @@ let main env = let addr = `Tcp (Eio_unix.Net.Ipaddr.of_unix inet, port) in let socket = Eio.Net.connect ~sw network addr in let connection = - H2_eio.Client.create_connection ~sw ~error_handler:ignore - (socket :> Eio.Flow.two_way) + H2_eio.Client.create_connection ~sw ~error_handler:ignore socket in let open Ocaml_protoc_plugin in diff --git a/examples/greeter-server-eio/greeter_server_eio.ml b/examples/greeter-server-eio/greeter_server_eio.ml index 13bfbf1..16aaba0 100644 --- a/examples/greeter-server-eio/greeter_server_eio.ml +++ b/examples/greeter-server-eio/greeter_server_eio.ml @@ -33,8 +33,7 @@ let connection_handler server sw = in fun socket addr -> H2_eio.Server.create_connection_handler ?config:None ~request_handler - ~error_handler addr - (socket :> Eio.Flow.two_way) + ~error_handler addr ~sw socket let serve server env = let port = 8080 in diff --git a/examples/routeguide-tutorial.md b/examples/routeguide-tutorial.md index 3cf7b66..c015536 100644 --- a/examples/routeguide-tutorial.md +++ b/examples/routeguide-tutorial.md @@ -285,7 +285,7 @@ Now let's look at something a little more complicated: the client-side streaming ```ocaml -let record_route (clock : #Eio.Time.clock) (stream : string Seq.t) = +let record_route (clock : _ Eio.Time.clock) (stream : string Seq.t) = Eio.traceln "RecordRoute"; let last_point = ref None in @@ -378,7 +378,7 @@ let serve server env = let clock = Eio.Stdenv.clock env in let addr = `Tcp (Eio.Net.Ipaddr.V4.loopback, port) in Eio.Switch.run @@ fun sw -> - let handler = connection_handler (server clock) sw in + let handler = connection_handler ~sw (server clock) in let server_socket = Eio.Net.listen net ~sw ~reuse_addr:true ~backlog:10 addr in @@ -425,8 +425,7 @@ let client ~sw host port network = in let addr = `Tcp (Eio_unix.Net.Ipaddr.of_unix inet, port) in let socket = Eio.Net.connect ~sw network addr in - H2_eio.Client.create_connection ~sw ~error_handler:ignore - (socket :> Eio.Flow.two_way) + H2_eio.Client.create_connection ~sw ~error_handler:ignore socket ``` To call service methods, we take the H2 connection and build up a gRPC call for the service method using `Client.call` from the Client module. diff --git a/examples/routeguide/src/client.ml b/examples/routeguide/src/client.ml index 5fed462..6baa1e0 100644 --- a/examples/routeguide/src/client.ml +++ b/examples/routeguide/src/client.ml @@ -15,8 +15,7 @@ let client ~sw host port network = in let addr = `Tcp (Eio_unix.Net.Ipaddr.of_unix inet, port) in let socket = Eio.Net.connect ~sw network addr in - H2_eio.Client.create_connection ~sw ~error_handler:ignore - (socket :> Eio.Flow.two_way) + H2_eio.Client.create_connection ~sw ~error_handler:ignore socket (* $MDX part-end *) (* $MDX part-begin=client-get-feature *) diff --git a/examples/routeguide/src/server.ml b/examples/routeguide/src/server.ml index 0c051ff..0ab6e3d 100644 --- a/examples/routeguide/src/server.ml +++ b/examples/routeguide/src/server.ml @@ -130,7 +130,7 @@ let list_features (buffer : string) (f : string -> unit) = (* $MDX part-end *) (* $MDX part-begin=server-record-route *) -let record_route (clock : #Eio.Time.clock) (stream : string Seq.t) = +let record_route (clock : _ Eio.Time.clock) (stream : string Seq.t) = Eio.traceln "RecordRoute"; let last_point = ref None in @@ -221,7 +221,7 @@ let server clock = ~service:(route_guide_service clock)) (* $MDX part-end *) -let connection_handler server sw = +let connection_handler server ~sw = let error_handler client_address ?request:_ _error start_response = Eio.traceln "Error in request from:%a" Eio.Net.Sockaddr.pp client_address; let response_body = start_response H2.Headers.empty in @@ -235,8 +235,7 @@ let connection_handler server sw = in fun socket addr -> H2_eio.Server.create_connection_handler ?config:None ~request_handler - ~error_handler addr - (socket :> Eio.Flow.two_way) + ~error_handler addr socket ~sw (* $MDX part-begin=server-main *) let serve server env = @@ -245,7 +244,7 @@ let serve server env = let clock = Eio.Stdenv.clock env in let addr = `Tcp (Eio.Net.Ipaddr.V4.loopback, port) in Eio.Switch.run @@ fun sw -> - let handler = connection_handler (server clock) sw in + let handler = connection_handler ~sw (server clock) in let server_socket = Eio.Net.listen net ~sw ~reuse_addr:true ~backlog:10 addr in