Lwt_utils: fix read_mbytes

This commit is contained in:
Vincent Bernardoff 2016-11-15 16:57:47 +01:00 committed by Grégoire Henry
parent 8680d98ecd
commit f7b149c9ed

View File

@ -242,8 +242,9 @@ let read_mbytes ?(pos=0) ?len fd buf =
if len = 0 then
Lwt.return_unit
else
Lwt_bytes.read fd buf pos len >>= fun nb_read ->
inner (pos + nb_read) (len - nb_read)
Lwt_bytes.read fd buf pos len >>= function
| 0 -> Lwt.fail End_of_file (* other endpoint cleanly closed its connection *)
| nb_read -> inner (pos + nb_read) (len - nb_read)
in
inner pos len