Skip to content

Commit 501063c

Browse files
committed
eio: Remove the use of 'Eio_unix.Fd.of_unix'
There's no easy way for opening a `Flow` through a `Eio_unix.Fd.t`. Instead, use `Eio_unix.Net.import_socket_stream` to create a `Flow` from a `Unix.file_descr` directly.
1 parent bf542d5 commit 501063c

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

bin/lwt_to_direct_style/concurrency_backend.ml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,24 @@ let eio ~eio_sw_as_fiber_var ~eio_env_as_fiber_var add_comment =
169169

170170
method direct_style_type param = param
171171

172-
method of_unix_file_descr ?blocking fd =
173-
let blocking_arg =
174-
let lbl = mk_loc "blocking" in
175-
match blocking with
176-
| Some (expr, `Lbl) -> [ (Labelled lbl, expr) ]
177-
| Some (expr, `Opt) -> [ (Optional lbl, expr) ]
178-
| None -> []
179-
in
180-
mk_apply_ident
181-
[ "Eio_unix"; "Fd"; "of_unix" ]
182-
([ get_current_switch_arg () ]
183-
@ blocking_arg
184-
@ [
185-
(Labelled (mk_loc "close_unix"), mk_constr_exp [ "true" ]);
186-
(Nolabel, fd);
187-
])
172+
method of_unix_file_descr ?blocking:_ fd =
173+
(* TODO: We don't use [Eio_unix.Fd.t] because there is no conversion to [Flow.sink]. *)
174+
(* let blocking_arg = *)
175+
(* let lbl = mk_loc "blocking" in *)
176+
(* match blocking with *)
177+
(* | Some (expr, `Lbl) -> [ (Labelled lbl, expr) ] *)
178+
(* | Some (expr, `Opt) -> [ (Optional lbl, expr) ] *)
179+
(* | None -> [] *)
180+
(* in *)
181+
(* mk_apply_ident *)
182+
(* [ "Eio_unix"; "Fd"; "of_unix" ] *)
183+
(* ([ get_current_switch_arg () ] *)
184+
(* @ blocking_arg *)
185+
(* @ [ *)
186+
(* (Labelled (mk_loc "close_unix"), mk_constr_exp [ "true" ]); *)
187+
(* (Nolabel, fd); *)
188+
(* ]) *)
189+
fd
188190

189191
method io_read input buffer buf_offset buf_len =
190192
add_comment "[%s] should be a [Cstruct.t]."
@@ -193,7 +195,9 @@ let eio ~eio_sw_as_fiber_var ~eio_env_as_fiber_var add_comment =
193195
add_comment_dropped_exp ~label:"buffer length" buf_len;
194196
mk_apply_simple [ "Eio"; "Flow"; "single_read" ] [ input; buffer ]
195197

196-
method fd_close fd = mk_apply_simple [ "Eio_unix"; "Fd" ] [ fd ]
198+
method fd_close fd =
199+
(* TODO: See [of_unix_file_descr]. mk_apply_simple [ "Eio_unix"; "Fd" ] [ fd ] *)
200+
mk_apply_simple [ "Unix"; "close" ] [ fd ]
197201

198202
method main_run promise =
199203
let with_binding var_ident x body =

test/lwt_to_direct_style/eio-switch.t/run.t

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ Make a writable directory tree:
3030
Fiber.fork
3131
~sw:(Stdlib.Option.get (Fiber.get Fiber_var.sw))
3232
(fun () -> async_process 1);
33-
let fd =
34-
Eio_unix.Fd.of_unix
35-
~sw:(Stdlib.Option.get (Fiber.get Fiber_var.sw))
36-
~close_unix:true Unix.stdin
37-
in
33+
let fd = Unix.stdin in
3834
let in_chan =
3935
(Eio_unix.Net.import_socket_stream
4036
~sw:(Stdlib.Option.get (Fiber.get Fiber_var.sw))

test/lwt_to_direct_style/to_direct_style.t/run.t

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,7 @@ Make a writable directory tree:
677677
678678
let _f fname =
679679
let inp =
680-
Eio_unix.Fd.of_unix ~sw ~close_unix:true
681-
(Unix
682-
(* TODO: lwt-to-direct-style: [sw] (of type Switch.t) must be propagated here. *).(
683-
openfile fname [ O_RDWR; O_NONBLOCK; O_APPEND ])
684-
0o660)
680+
Unix.(openfile fname [ O_RDWR; O_NONBLOCK; O_APPEND ]) 0o660
685681
|>
686682
(* TODO: lwt-to-direct-style: [sw] (of type Switch.t) must be propagated here. *)
687683
(* TODO: lwt-to-direct-style: This creates a closeable [Flow.source] resource but read operations are rewritten to calls to [Buf_read]. *)

0 commit comments

Comments
 (0)