Skip to content

Commit

Permalink
chore: update flakes and ocamlformat (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Sep 17, 2023
1 parent 5bd21ca commit 3c44768
Show file tree
Hide file tree
Showing 32 changed files with 805 additions and 826 deletions.
56 changes: 28 additions & 28 deletions bin/carl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ let rec uri_of_string ~scheme s =
(* If Uri.of_string didn't get a host it must mean that the scheme wasn't
* even present. *)
Logs.debug (fun m ->
m "Protocol not provided for %s. Using the default scheme: %s" s scheme);
m "Protocol not provided for %s. Using the default scheme: %s" s scheme);
uri_of_string ~scheme ("//" ^ s)
| Some _, None ->
(* e.g. `//example.com` *)
Expand Down Expand Up @@ -245,18 +245,18 @@ let handle_response
| Channel filename ->
(try
Eio_unix.run_in_systhread (fun () ->
let fd =
Unix.openfile
filename
Unix.[ O_NONBLOCK; O_WRONLY; O_TRUNC; O_CREAT ]
0o600
in
let fd = Eio_unix.Fd.of_unix ~sw ~close_unix:true fd in
Ok
( fd
, Format.formatter_of_out_channel
(Unix.out_channel_of_descr
(Eio_unix.Fd.use_exn "handle_response" fd Fun.id)) ))
let fd =
Unix.openfile
filename
Unix.[ O_NONBLOCK; O_WRONLY; O_TRUNC; O_CREAT ]
0o600
in
let fd = Eio_unix.Fd.of_unix ~sw ~close_unix:true fd in
Ok
( fd
, Format.formatter_of_out_channel
(Unix.out_channel_of_descr
(Eio_unix.Fd.use_exn "handle_response" fd Fun.id)) ))
with
| exn -> Error (`Exn exn))
in
Expand All @@ -268,8 +268,8 @@ let handle_response
if head
then (
Fiber.fork ~sw (fun () ->
let (_ : (unit, _) result) = Body.drain body in
());
let (_ : (unit, _) result) = Body.drain body in
());
ok)
else
match compressed, Headers.get response.headers "content-encoding" with
Expand Down Expand Up @@ -317,7 +317,7 @@ let handle_response
| Stdout | Channel "-" -> Format.pp_print_newline formatter ()
| Channel _ ->
Eio_unix.run_in_systhread (fun () ->
Unix.close (Eio_unix.Fd.use_exn "close" channel Fun.id)));
Unix.close (Eio_unix.Fd.use_exn "close" channel Fun.id)));
result

let build_headers
Expand All @@ -337,8 +337,8 @@ let build_headers
match oauth2_bearer, user with
| Some token, _ ->
Logs.debug (fun m ->
let user = match user with Some user -> user | None -> "''" in
m "Server authorization using Bearer with user %s" user);
let user = match user with Some user -> user | None -> "''" in
m "Server authorization using Bearer with user %s" user);
(* Bearer token overrides `user` *)
("Authorization", "Bearer " ^ token) :: headers
| None, Some user ->
Expand Down Expand Up @@ -370,17 +370,17 @@ let request env ~sw ~cli ~config uri =
let flow = Eio_unix.Net.import_socket_stream ~sw ~close_unix:true fd in
let stream =
Stream.from ~f:(fun () ->
if !remaining = 0
then None
else
let len = min config.Config.body_buffer_size !remaining in
let cs = Cstruct.create len in
Eio.Flow.read_exact flow cs;
remaining := !remaining - len;
Some { Faraday.buffer = cs.buffer; off = cs.off; len = cs.len })
if !remaining = 0
then None
else
let len = min config.Config.body_buffer_size !remaining in
let cs = Cstruct.create len in
Eio.Flow.read_exact flow cs;
remaining := !remaining - len;
Some { Faraday.buffer = cs.buffer; off = cs.off; len = cs.len })
in
Fiber.fork ~sw (fun () ->
Stream.when_closed ~f:(fun () -> Eio.Flow.close flow) stream);
Stream.when_closed ~f:(fun () -> Eio.Flow.close flow) stream);
let body_length =
match
List.find_opt
Expand Down Expand Up @@ -469,7 +469,7 @@ let main ({ log_level; urls; _ } as cli) =
| Error msg -> `Error (false, msg)
| Ok config ->
Eio_main.run (fun env ->
Eio.Switch.run (fun sw -> request_many ~sw ~cli ~config env urls))
Eio.Switch.run (fun sw -> request_many ~sw ~cli ~config env urls))

(* --resolve <host:port:address[,address]...> Resolve the host+port to this address
* --retry <num> Retry request if transient problems occur
Expand Down
12 changes: 6 additions & 6 deletions examples/docs/readme.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ let get_sync env ~sw url =

let () =
Eio_main.run (fun env ->
Eio.Switch.run (fun sw ->
match get_sync env ~sw "https://example.com" with
| Ok body -> print_endline body
| Error error ->
let message = Error.to_string error in
prerr_endline ("Error: " ^ message)))
Eio.Switch.run (fun sw ->
match get_sync env ~sw "https://example.com" with
| Ok body -> print_endline body
| Error error ->
let message = Error.to_string error in
prerr_endline ("Error: " ^ message)))
26 changes: 13 additions & 13 deletions examples/eio/echo_server_upgrade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ open Piaf

let connection_handler { Server.request; _ } =
Response.Upgrade.websocket request ~f:(fun wsd ->
let frames = Ws.Descriptor.messages wsd in
Stream.iter
~f:(fun (_opcode, frame) -> Ws.Descriptor.send_iovec wsd frame)
frames)
let frames = Ws.Descriptor.messages wsd in
Stream.iter
~f:(fun (_opcode, frame) -> Ws.Descriptor.send_iovec wsd frame)
frames)
|> Result.get_ok

let setup_log ?style_renderer level =
Expand All @@ -23,12 +23,12 @@ let () =
ignore
"Echoes websocket messages. Runs forever.";
Eio_main.run (fun env ->
Switch.run (fun sw ->
let config =
Server.Config.create (`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
in
let server = Server.create ~config connection_handler in
let _command = Server.Command.start ~sw env server in
()
(* Eio.Time.sleep (Eio.Stdenv.clock env) 5.; *)
(* Server.Command.shutdown command *)))
Switch.run (fun sw ->
let config =
Server.Config.create (`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
in
let server = Server.create ~config connection_handler in
let _command = Server.Command.start ~sw env server in
()
(* Eio.Time.sleep (Eio.Stdenv.clock env) 5.; *)
(* Server.Command.shutdown command *)))
12 changes: 6 additions & 6 deletions examples/eio/eio_echo_post.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ let main port =
(`Tcp (Eio.Net.Ipaddr.V4.loopback, port)))
in
Eio_main.run (fun env ->
Switch.run (fun sw ->
let server = Server.create ~config request_handler in
let _command = Server.Command.start ~sw env server in
()
(* Eio.Time.sleep (Eio.Stdenv.clock env) 5.; *)
(* Server.Command.shutdown command *)))
Switch.run (fun sw ->
let server = Server.create ~config request_handler in
let _command = Server.Command.start ~sw env server in
()
(* Eio.Time.sleep (Eio.Stdenv.clock env) 5.; *)
(* Server.Command.shutdown command *)))

let setup_log ?style_renderer level =
Fmt_tty.setup_std_outputs ?style_renderer ();
Expand Down
8 changes: 4 additions & 4 deletions examples/eio/eio_get.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let () =
| Some host -> host
in
Eio_main.run (fun env ->
Eio.Switch.run (fun sw ->
match request ~sw ~env host with
| Ok () -> ()
| Error e -> failwith (Piaf.Error.to_string e)))
Eio.Switch.run (fun sw ->
match request ~sw ~env host with
| Ok () -> ()
| Error e -> failwith (Piaf.Error.to_string e)))
16 changes: 8 additions & 8 deletions examples/eio/eio_multidomain_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ let start env =
let host = Eio.Net.Ipaddr.V4.loopback
and port = 8080 in
Switch.run (fun sw ->
let config =
Server.Config.create
~buffer_size:0x1000
~domains:recommended_domain_count
(`Tcp (host, port))
in
let server = Server.create ~config connection_handler in
ignore (Server.Command.start ~sw env server : Server.Command.t))
let config =
Server.Config.create
~buffer_size:0x1000
~domains:recommended_domain_count
(`Tcp (host, port))
in
let server = Server.create ~config connection_handler in
ignore (Server.Command.start ~sw env server : Server.Command.t))

let setup_log ?style_renderer level =
Logs_threaded.enable ();
Expand Down
6 changes: 3 additions & 3 deletions examples/eio/eio_server_get.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ let setup_log ?style_renderer level =
let () =
setup_log (Some Info);
Eio_main.run (fun env ->
Switch.run (fun sw ->
let _command = start ~sw env in
()))
Switch.run (fun sw ->
let _command = start ~sw env in
()))
24 changes: 12 additions & 12 deletions examples/eio/eio_wscat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ let request ~env ~sw host =
let+ wsd = Client.ws_upgrade client "/" in
Fiber.both
(fun () ->
let stdin = Eio.Stdenv.stdin env in
let buf = Eio.Buf_read.of_flow stdin ~initial_size:100 ~max_size:1_000 in
stdin_loop ~stdin buf wsd;
Client.shutdown client)
let stdin = Eio.Stdenv.stdin env in
let buf = Eio.Buf_read.of_flow stdin ~initial_size:100 ~max_size:1_000 in
stdin_loop ~stdin buf wsd;
Client.shutdown client)
(fun () ->
Stream.iter
~f:(fun (_opcode, { IOVec.buffer; off; len }) ->
Format.printf ">> %s@." (Bigstringaf.substring ~off ~len buffer))
(Ws.Descriptor.messages wsd))
Stream.iter
~f:(fun (_opcode, { IOVec.buffer; off; len }) ->
Format.printf ">> %s@." (Bigstringaf.substring ~off ~len buffer))
(Ws.Descriptor.messages wsd))

let setup_log ?style_renderer level =
Fmt_tty.setup_std_outputs ?style_renderer ();
Expand All @@ -63,7 +63,7 @@ let () =
| Some host -> host
in
Eio_main.run (fun env ->
Eio.Switch.run (fun sw ->
match request ~sw ~env host with
| Ok () -> ()
| Error e -> failwith (Piaf.Error.to_string e)))
Eio.Switch.run (fun sw ->
match request ~sw ~env host with
| Ok () -> ()
| Error e -> failwith (Piaf.Error.to_string e)))
27 changes: 13 additions & 14 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/anmonteiro/eio-0.12";
url = "github:nix-ocaml/nix-overlays";
inputs.flake-utils.follows = "flake-utils";
};

Expand Down
Loading

0 comments on commit 3c44768

Please sign in to comment.