Skip to content

Commit

Permalink
feat(websocketaf-eio): track sw for gluten (#52)
Browse files Browse the repository at this point in the history
* feat(websocketaf-eio): track sw for gluten

* update flake

* don't require close

* fix: gh actions

* fix: examples
  • Loading branch information
anmonteiro authored Jul 9, 2023
1 parent a1c3db2 commit cf9b528
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ocamlVersion: [4_12, 4_13, 4_14, 5_00]
ocamlVersion: [4_14, 5_0, 5_1]
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v17
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v22
with:
extra_nix_config: |
extra-substituters = https://anmonteiro.nix-cache.workers.dev
Expand Down
28 changes: 15 additions & 13 deletions eio/websocketaf_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ module Server = struct
let create_connection_handler
?(config = Httpaf.Config.default)
~websocket_handler
~error_handler = fun client_addr socket ->
let connection =
Websocketaf.Server_connection.create
~sha1
~error_handler:(error_handler client_addr)
(websocket_handler client_addr)
in
Gluten_eio.Server.create_connection_handler
~read_buffer_size:config.read_buffer_size
~protocol:(module Websocketaf.Server_connection)
connection
client_addr
socket
~error_handler ~sw =
fun client_addr socket ->
let connection =
Websocketaf.Server_connection.create
~sha1
~error_handler:(error_handler client_addr)
(websocket_handler client_addr)
in
Gluten_eio.Server.create_connection_handler
~read_buffer_size:config.read_buffer_size
~protocol:(module Websocketaf.Server_connection)
~sw
connection
client_addr
socket
end

module Client = struct
Expand Down
5 changes: 3 additions & 2 deletions eio/websocketaf_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Server : sig
: ?config : Httpaf.Config.t
-> websocket_handler : (Eio.Net.Sockaddr.stream -> Wsd.t -> Websocket_connection.input_handlers)
-> error_handler : (Eio.Net.Sockaddr.stream -> Server_connection.error_handler)
-> (Eio.Net.Sockaddr.stream -> Eio.Flow.two_way -> unit)
-> sw:Eio.Switch.t
-> (Eio.Net.Sockaddr.stream -> #Eio.Flow.two_way -> unit)
end

module Client : sig
Expand All @@ -22,7 +23,7 @@ module Client : sig
-> resource : string
-> error_handler : (Client_connection.error -> unit)
-> websocket_handler : (Wsd.t -> Websocket_connection.input_handlers)
-> Eio.Flow.two_way
-> #Eio.Flow.two_way
-> t

val is_closed : t -> bool
Expand Down
5 changes: 3 additions & 2 deletions examples/eio/echo_server.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let connection_handler : Eio.Net.Sockaddr.stream -> Eio.Net.stream_socket -> unit =
let connection_handler ~sw : Eio.Net.Sockaddr.stream -> Eio.Net.stream_socket -> unit =
let module Body = Httpaf.Body in
let module Headers = Httpaf.Headers in
let module Reqd = Httpaf.Reqd in
Expand Down Expand Up @@ -42,6 +42,7 @@ let connection_handler : Eio.Net.Sockaddr.stream -> Eio.Net.stream_socket -> uni
?config:None
~websocket_handler
~error_handler
~sw


let () =
Expand Down Expand Up @@ -69,7 +70,7 @@ let () =
while true do
Eio.Net.accept_fork socket ~sw ~on_error:(fun _ -> assert false) (fun client_sock client_addr ->
(* let p, u = Eio.Promise.create () in *)
connection_handler client_addr client_sock)
connection_handler ~sw client_addr client_sock)
done;
`Stop_daemon)))
done;
Expand Down
2 changes: 1 addition & 1 deletion examples/eio/echo_server_upgrade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let () =
while true do
Eio.Net.accept_fork socket ~sw ~on_error:(fun _ -> assert false) (fun client_sock client_addr ->
(* let p, u = Eio.Promise.create () in *)
connection_handler client_addr client_sock)
connection_handler ~sw client_addr client_sock)
done;
`Stop_daemon)))
done;
Expand Down
45 changes: 32 additions & 13 deletions flake.lock

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

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
inputs.nix-filter.url = "github:numtide/nix-filter";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.url = "github:anmonteiro/nix-overlays";
inputs.nixpkgs.url = "github:anmonteiro/nix-overlays/anmonteiro/update-gluten-piaf";

outputs = { self, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}".extend (self: super: {
pkgs = nixpkgs.legacyPackages.${system}.extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_0;
});
in
Expand Down

0 comments on commit cf9b528

Please sign in to comment.