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

Expose eio backend in posix, windows, and linux backends #560

Merged
merged 1 commit into from
Jun 20, 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
1 change: 1 addition & 0 deletions lib_eio/eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Stdenv = struct
let fs (t : <fs : #Fs.dir Path.t; ..>) = t#fs
let cwd (t : <cwd : #Fs.dir Path.t; ..>) = t#cwd
let debug (t : <debug : 'a; ..>) = t#debug
let backend_id (t: <backend_id : string; ..>) = t#backend_id
end

exception Io = Exn.Io
6 changes: 6 additions & 0 deletions lib_eio/eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ module Stdenv : sig

val debug : <debug : <Debug.t; ..> as 'a; ..> -> 'a
(** [debug t] provides privileged controls for debugging. *)

val backend_id : <backend_id:string; ..> -> string
(** [backend_id t] provides the name of the backend being used.

The possible values are the same as the possible values of the "EIO_BACKEND"
environment variable used by {!Eio_main.run}. *)
end

(** {1 Errors and Debugging} *)
Expand Down
1 change: 1 addition & 0 deletions lib_eio/unix/eio_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ module Stdenv = struct
cwd : Eio.Fs.dir Eio.Path.t;
secure_random : Eio.Flow.source;
debug : Eio.Debug.t;
backend_id: string;
>
end
1 change: 1 addition & 0 deletions lib_eio/unix/eio_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module Stdenv : sig
cwd : Eio.Fs.dir Eio.Path.t;
secure_random : Eio.Flow.source;
debug : Eio.Debug.t;
backend_id : string;
>
(** The common set of features provided by all traditional operating systems (BSDs, Linux, Mac, Windows).

Expand Down
1 change: 1 addition & 0 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ let stdenv ~run_event_loop =
method cwd = (cwd :> Eio.Fs.dir Eio.Path.t)
method secure_random = secure_random
method debug = Eio.Private.Debug.v
method backend_id = "linux"
end

let run_event_loop (type a) ?fallback config (main : _ -> a) arg : a =
Expand Down
6 changes: 6 additions & 0 deletions lib_eio_linux/tests/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ let test_read_exact () =
let got = Uring.Region.to_string chunk ~len:(String.length msg) in
if got <> msg then Fmt.failwith "%S vs %S" got msg

let test_expose_backend () =
Eio_linux.run @@ fun env ->
let backend = Eio.Stdenv.backend_id env in
assert (backend = "linux")

let () =
let open Alcotest in
run "eio_linux" [
Expand All @@ -161,5 +166,6 @@ let () =
test_case "iovec" `Quick test_iovec;
test_case "no_sqe" `Quick test_no_sqe;
test_case "read_exact" `Quick test_read_exact;
test_case "expose_backend" `Quick test_expose_backend;
];
]
1 change: 1 addition & 0 deletions lib_eio_posix/eio_posix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ let run main =
method cwd = ((Fs.cwd, "") :> Eio.Fs.dir Eio.Path.t)
method fs = ((Fs.fs, "") :> Eio.Fs.dir Eio.Path.t)
method secure_random = Flow.secure_random
method backend_id = "posix"
end
1 change: 1 addition & 0 deletions lib_eio_windows/eio_windows.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ let run main =
method fs = ((Fs.fs, "") :> Eio.Fs.dir Eio.Path.t)
method process_mgr = failwith "process operations not supported on Windows yet"
method secure_random = Flow.secure_random
method backend_id = "windows"
end