Skip to content

Commit 3c6d07a

Browse files
committed
Make pipes nonblocking in Eio_unix.pipe, zap Eio_linux.pipe
Make sure we use pipes as nonblocking see #319 in Eio_unix.pipe. Zap Eio_linux.pipe since it's only used in tests.
1 parent 63f5896 commit 3c6d07a

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

lib_eio_linux/eio_linux.ml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,15 +1292,6 @@ let stdenv ~run_event_loop =
12921292
method debug = Eio.Private.Debug.v
12931293
end
12941294

1295-
let pipe sw =
1296-
let r, w = Unix.pipe () in
1297-
(* XXX workaround for issue #319, PR #327 *)
1298-
Unix.set_nonblock r;
1299-
Unix.set_nonblock w;
1300-
let r = source (FD.of_unix ~sw ~seekable:false ~close_unix:true r) in
1301-
let w = sink (FD.of_unix ~sw ~seekable:false ~close_unix:true w) in
1302-
r, w
1303-
13041295
let monitor_event_fd t =
13051296
let buf = Cstruct.create 8 in
13061297
while true do
@@ -1455,6 +1446,9 @@ let rec run : type a.
14551446
)
14561447
| Eio_unix.Private.Pipe sw -> Some (fun k ->
14571448
let r, w = Unix.pipe ~cloexec:true () in
1449+
(* See issue #319, PR #327 *)
1450+
Unix.set_nonblock r;
1451+
Unix.set_nonblock w;
14581452
let r = (flow (FD.of_unix ~sw ~seekable:false ~close_unix:true r) :> <Eio.Flow.source; Eio.Flow.close; Eio_unix.unix_fd>) in
14591453
let w = (flow (FD.of_unix ~sw ~seekable:false ~close_unix:true w) :> <Eio.Flow.sink; Eio.Flow.close; Eio_unix.unix_fd>) in
14601454
continue k (r, w)

lib_eio_linux/eio_linux.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ type stdenv = <
7474
val get_fd : <has_fd; ..> -> FD.t
7575
val get_fd_opt : #Eio.Generic.t -> FD.t option
7676

77-
val pipe : Switch.t -> source * sink
78-
(** [pipe sw] is a source-sink pair [(r, w)], where data written to [w] can be read from [r].
79-
It is implemented as a Unix pipe. *)
80-
8177
(** {1 Main Loop} *)
8278

8379
val run :

lib_eio_linux/tests/test.ml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let read_one_byte ~sw r =
2020
let test_poll_add () =
2121
Eio_linux.run @@ fun _stdenv ->
2222
Switch.run @@ fun sw ->
23-
let r, w = Eio_linux.pipe sw in
23+
let r, w = Eio_unix.pipe sw in
2424
let thread = read_one_byte ~sw r in
2525
Fiber.yield ();
2626
let w = Option.get (Eio_linux.get_fd_opt w) in
@@ -33,7 +33,7 @@ let test_poll_add () =
3333
let test_poll_add_busy () =
3434
Eio_linux.run ~queue_depth:2 @@ fun _stdenv ->
3535
Switch.run @@ fun sw ->
36-
let r, w = Eio_linux.pipe sw in
36+
let r, w = Eio_unix.pipe sw in
3737
let a = read_one_byte ~sw r in
3838
let b = read_one_byte ~sw r in
3939
Fiber.yield ();
@@ -50,7 +50,7 @@ let test_copy () =
5050
Eio_linux.run ~queue_depth:3 @@ fun _stdenv ->
5151
Switch.run @@ fun sw ->
5252
let msg = "Hello!" in
53-
let from_pipe, to_pipe = Eio_linux.pipe sw in
53+
let from_pipe, to_pipe = Eio_unix.pipe sw in
5454
let buffer = Buffer.create 20 in
5555
Fiber.both
5656
(fun () -> Eio.Flow.copy from_pipe (Eio.Flow.buffer_sink buffer))
@@ -67,8 +67,8 @@ let test_direct_copy () =
6767
Eio_linux.run ~queue_depth:4 @@ fun _stdenv ->
6868
Switch.run @@ fun sw ->
6969
let msg = "Hello!" in
70-
let from_pipe1, to_pipe1 = Eio_linux.pipe sw in
71-
let from_pipe2, to_pipe2 = Eio_linux.pipe sw in
70+
let from_pipe1, to_pipe1 = Eio_unix.pipe sw in
71+
let from_pipe2, to_pipe2 = Eio_unix.pipe sw in
7272
let buffer = Buffer.create 20 in
7373
let to_output = Eio.Flow.buffer_sink buffer in
7474
Switch.run (fun sw ->
@@ -85,9 +85,15 @@ let test_direct_copy () =
8585
let test_iovec () =
8686
Eio_linux.run ~queue_depth:4 @@ fun _stdenv ->
8787
Switch.run @@ fun sw ->
88-
let from_pipe, to_pipe = Eio_linux.pipe sw in
89-
let from_pipe = Eio_linux.get_fd from_pipe in
90-
let to_pipe = Eio_linux.get_fd to_pipe in
88+
let from_pipe, to_pipe = Eio_unix.pipe sw in
89+
let from_pipe =
90+
Eio_unix.FD.take from_pipe |>
91+
Eio_linux.FD.of_unix ~sw ~seekable:false ~close_unix:true
92+
in
93+
let to_pipe =
94+
Eio_unix.FD.take to_pipe |>
95+
Eio_linux.FD.of_unix ~sw ~seekable:false ~close_unix:true
96+
in
9197
let message = Cstruct.of_string "Got [ ] and [ ]" in
9298
let rec recv = function
9399
| [] -> ()

0 commit comments

Comments
 (0)