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

CA-387588: Unixext.really_read: restart on EINTR #86

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/xapi-stdext-unix/unixext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,6 @@ let proxy (a : Unix.file_descr) (b : Unix.file_descr) =
try Unix.close b with _ -> ()
)

let rec really_read fd string off n =
if n = 0 then
()
else
let m = Unix.read fd string off n in
if m = 0 then raise End_of_file ;
really_read fd string (off + m) (n - m)

let really_read_string fd length =
let buf = Bytes.make length '\000' in
really_read fd buf 0 length ;
Bytes.unsafe_to_string buf

let try_read_string ?limit fd =
let buf = Buffer.create 0 in
let chunk = match limit with None -> 4096 | Some x -> x in
Expand Down Expand Up @@ -523,6 +510,19 @@ and really_write fd buffer offset len =
let really_write_string fd string =
really_write fd string 0 (String.length string)

let rec really_read fd string off n =
if n = 0 then
()
else
let m = restart_on_EINTR (Unix.read fd string off) n in
if m = 0 then raise End_of_file ;
really_read fd string (off + m) (n - m)

let really_read_string fd length =
let buf = Bytes.make length '\000' in
really_read fd buf 0 length ;
Bytes.unsafe_to_string buf

(* --------------------------------------------------------------------------------------- *)
(* Functions to read and write to/from a file descriptor with a given latest response time *)

Expand Down
Loading