miragesdk: fail early on short read/write returning 0
@@ -9,7 +9,8 @@ let rec really_write fd buf off len =
| len ->
Log.debug (fun l -> l "really_write off=%d len=%d" off len);
Lwt_unix.write fd buf off len >>= fun n ->
- really_write fd buf (off+n) (len-n)
+ if n = 0 then Lwt.fail_with "write 0"
+ else really_write fd buf (off+n) (len-n)
let write fd buf = really_write fd buf 0 (String.length buf)
@@ -19,7 +20,8 @@ let rec really_read fd buf off len =
| len ->
Log.debug (fun l -> l "really_read off=%d len=%d" off len);
Lwt_unix.read fd buf off len >>= fun n ->
- really_read fd buf (off+n) (len-n)
+ if n = 0 then Lwt.fail_with "read 0"
+ else really_read fd buf (off+n) (len-n)
let read_all fd =
Log.debug (fun l -> l "read_all");
@@ -27,6 +29,8 @@ let read_all fd =
let buf = Bytes.create len in
let rec loop acc =
Lwt_unix.read fd buf 0 len >>= fun n ->
+ if n = 0 then Lwt.fail_with "read 0"
+ else
let acc = String.sub buf 0 n :: acc in
if n <= len then Lwt.return (List.rev acc)
else loop acc
@@ -39,6 +43,8 @@ let read_n fd len =
let buf = Bytes.create len in
let rec loop acc len =
Lwt_unix.read fd buf 0 len >>= fun n ->
+ if n = 0 then Lwt.fail_with "read 0"
+ else
let acc = String.sub buf 0 n :: acc in
match len - n with
| 0 -> Lwt.return (List.rev acc)
