Skip to content

Commit

Permalink
Update example code for Eio.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Nov 5, 2023
1 parent d4895ab commit 3886b31
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions examples/greeter-client-eio/greeter_client_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/greeter-server-eio/greeter_server_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions examples/routeguide-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Now let's look at something a little more complicated: the client-side streaming
<!-- $MDX include,file=routeguide/src/server.ml,part=server-record-route -->
```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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions examples/routeguide/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
9 changes: 4 additions & 5 deletions examples/routeguide/src/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 3886b31

Please sign in to comment.