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

on Windows, reading from stdin blocks the whole domain. #793

Closed
bdodrem opened this issue Jan 11, 2025 · 1 comment
Closed

on Windows, reading from stdin blocks the whole domain. #793

bdodrem opened this issue Jan 11, 2025 · 1 comment

Comments

@bdodrem
Copy link
Contributor

bdodrem commented Jan 11, 2025

I tried to read a line from stdin with a timeout (code below). On Windows, the process blocks until I press Enter (not on Linux).
So I guess, reading the stdin on Windows blocks the whole domain.

open Eio.Std
open Eio.Buf_read
let _ = Eio_main.run (fun env -> 
    let readoneline () = traceln "%s" @@ parse_exn ~max_size:1024 line env#stdin  in
    Eio.Time.with_timeout_exn env#clock 2. readoneline
  )

Running the code :

$ cat | dune exec ./test.exe

blocks untill Enter is pressed

@talex5
Copy link
Collaborator

talex5 commented Jan 14, 2025

Probably needs a check for this. I see posix has one, but windows doesn't:

let read fd buf start len =
if Fd.is_blocking fd then await_readable "read" fd;
Fd.use_exn "read" fd @@ fun fd ->
do_nonblocking Read "read" (fun fd -> Unix.read fd buf start len) fd

let read fd buf start len =
Fd.use_exn "read" fd @@ fun fd ->
do_nonblocking Read (fun fd -> Unix.read fd buf start len) fd

bdodrem added a commit to bdodrem/eio that referenced this issue Jan 25, 2025
      Adding await_readable before reading fd

- fix broken pipe exception : issue ocaml-multicore#792.
      Use Unix.read_bigarray instead of Unix_cstruct.read

- replace eio_windows_cstruct_stubs.c by Unix functions.
      Unix.read_bigarray and Unix.write_bigarray implemented since Ocaml 5.2
bdodrem added a commit to bdodrem/eio that referenced this issue Jan 25, 2025
      Adding await_readable before reading fd

* fix broken pipe exception : issue ocaml-multicore#792.
      Use Unix.read_bigarray instead of Unix_cstruct.read

* replace eio_windows_cstruct_stubs.c by Unix functions.
     Since Ocaml 5.2, Unix.read_bigarray and Unix.write_bigarray can be used.
talex5 pushed a commit to bdodrem/eio that referenced this issue Jan 27, 2025
* fix blocking issue on Windows : issue ocaml-multicore#793.
      Adding await_readable before reading fd

* fix broken pipe exception : issue ocaml-multicore#792.
      Use Unix.read_bigarray instead of Unix_cstruct.read

* replace eio_windows_cstruct_stubs.c by Unix functions.
     Since OCaml 5.2, Unix.read_bigarray and Unix.write_bigarray can be used.
talex5 pushed a commit to bdodrem/eio that referenced this issue Jan 27, 2025
* fix blocking issue on Windows : issue ocaml-multicore#793.
      Adding await_readable before reading fd

* fix broken pipe exception : issue ocaml-multicore#792.
      Use Unix.read_bigarray instead of Unix_cstruct.read

* replace eio_windows_cstruct_stubs.c by Unix functions.
     Since OCaml 5.2, Unix.read_bigarray and Unix.write_bigarray can be used.
talex5 added a commit that referenced this issue Jan 27, 2025
…d_792

On Windows, fix stdin broken-pipe and blocking domain.  Issues #793 and #792.
@talex5 talex5 closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants