Skip to content

Commit

Permalink
fix(sendfile): don't propagate Darwin_specific exception (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Sep 28, 2023
1 parent 9ec58d0 commit d9c3c45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions sendfile/sendfile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ external sendfile :
-> int
= "ocaml_sendfile_sendfile_stub"

let sendfile_once_exn ?(off = 0) ~len ~src dst = sendfile ~src ~dst ~off ~len
let sendfile_once_exn ?(off = 0) ~len ~src dst =
try sendfile ~src ~dst ~off ~len with
| Darwin_specific_unix_error (unix_err, _) ->
raise (Unix.Unix_error (unix_err, "sendfile", ""))

let sendfile_once ?(off = 0) ~len ~src dst =
try Ok (sendfile_once_exn ~src ~off ~len dst) with
| Unix.Unix_error (unix_err, _, _msg) -> Error unix_err

let sendfile_exn ?(off = 0) ?len ~src dst =
let rec sendfile_exn ~off ~len ~src dst =
match sendfile_once_exn ~src ~off ~len dst with
match sendfile ~src ~off ~len ~dst with
| c when c = len -> len
| c -> sendfile_exn ~src ~off:(off + c) ~len:(len - c) dst
| exception Unix.Unix_error ((EINTR | EAGAIN), _, _) ->
Expand All @@ -110,6 +113,8 @@ let sendfile_exn ?(off = 0) ?len ~src dst =
(* Darwin systems signal the number of bytes partially sent on EINTR /
EAGAIN. *)
sendfile_exn ~src ~off:(off + sent) ~len:(len - sent) dst
| exception Darwin_specific_unix_error (unix_err, _) ->
raise (Unix.Unix_error (unix_err, "sendfile", ""))
in
let len =
match len with Some len -> len | None -> (Unix.fstat src).st_size - off
Expand Down

0 comments on commit d9c3c45

Please sign in to comment.