Skip to content

Commit

Permalink
Merge pull request #795 from bdodrem/windows_read-stdin__issue_793_an…
Browse files Browse the repository at this point in the history
…d_792

On Windows, fix stdin broken-pipe and blocking domain.  Issues #793 and #792.
  • Loading branch information
talex5 authored Jan 27, 2025
2 parents c78db1a + d3cb04a commit 8f7f82d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
os:
- macos-latest
ocaml-compiler:
- 5.1.x
- 5.2.x
local-packages:
- eio eio_posix eio_main

Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
with:
opam-pin: false
opam-depext: false
ocaml-compiler: ocaml.5.1.0,ocaml-option-mingw
ocaml-compiler: ocaml.5.2.0,ocaml-option-mingw
opam-repositories: |
dra27: https://github.com/dra27/opam-repository.git#windows-5.0
normal: https://github.com/ocaml/opam-repository.git
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(description "An effect-based IO API for multicore OCaml with fibers.")
(conflicts (seq (< 0.3)))
(depends
(ocaml (>= 5.1.0))
(ocaml (>= 5.2.0))
(bigstringaf (>= 0.9.0))
(cstruct (>= 6.0.1))
lwt-dllist
Expand Down
2 changes: 1 addition & 1 deletion eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doc: "https://ocaml-multicore.github.io/eio/"
bug-reports: "https://github.com/ocaml-multicore/eio/issues"
depends: [
"dune" {>= "3.9"}
"ocaml" {>= "5.1.0"}
"ocaml" {>= "5.2.0"}
"bigstringaf" {>= "0.9.0"}
"cstruct" {>= "6.0.1"}
"lwt-dllist"
Expand Down
2 changes: 1 addition & 1 deletion lib_eio_windows/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(foreign_stubs
(language c)
(include_dirs ../lib_eio/unix/include)
(names eio_windows_stubs eio_windows_cstruct_stubs))
(names eio_windows_stubs))
(c_library_flags :standard -lbcrypt -lntdll)
(libraries eio eio.unix eio.utils fmt))

Expand Down
149 changes: 0 additions & 149 deletions lib_eio_windows/eio_windows_cstruct_stubs.c

This file was deleted.

19 changes: 15 additions & 4 deletions lib_eio_windows/low_level.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,25 @@ let rec do_nonblocking ty fn fd =
do_nonblocking ty fn fd

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

let read_cstruct fd buf =
let read_cstruct fd (buf:Cstruct.t) =
await_readable fd;
Fd.use_exn "read_cstruct" fd @@ fun fd ->
do_nonblocking Read (fun fd -> Unix_cstruct.read fd buf) fd
do_nonblocking Read (fun fd -> Unix.read_bigarray fd buf.buffer buf.off buf.len) fd

let write fd buf start len =
await_writable fd;
Fd.use_exn "write" fd @@ fun fd ->
do_nonblocking Write (fun fd -> Unix.write fd buf start len) fd

let write_cstruct fd (buf:Cstruct.t) =
await_writable fd;
Fd.use_exn "write_cstruct" fd @@ fun fd ->
do_nonblocking Write (fun fd -> Unix.write_bigarray fd buf.buffer buf.off buf.len) fd

let sleep_until time =
Sched.enter @@ fun t k ->
Sched.await_timeout t k time
Expand Down Expand Up @@ -148,8 +156,11 @@ let readv fd bufs =
do_nonblocking Read (fun fd -> eio_readv fd bufs) fd

let writev fd bufs =
Fd.use_exn "writev" fd @@ fun fd ->
do_nonblocking Write (fun fd -> Unix_cstruct.writev fd bufs) fd
let rec loop buf = if Cstruct.length buf > 0 then begin
let n = write_cstruct fd buf in
loop @@ Cstruct.shift buf n
end in
List.iter loop bufs

let preadv ~file_offset fd bufs =
Fd.use_exn "preadv" fd @@ fun fd ->
Expand Down
1 change: 1 addition & 0 deletions lib_eio_windows/low_level.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ val sleep_until : Mtime.t -> unit
val read : fd -> bytes -> int -> int -> int
val read_cstruct : fd -> Cstruct.t -> int
val write : fd -> bytes -> int -> int -> int
val write_cstruct : fd -> Cstruct.t -> int

val socket : sw:Switch.t -> Unix.socket_domain -> Unix.socket_type -> int -> fd
val connect : fd -> Unix.sockaddr -> unit
Expand Down

0 comments on commit 8f7f82d

Please sign in to comment.