From f7b149c9ed6a29c2ae259fe56feb04c7fc9191bc Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Tue, 15 Nov 2016 16:57:47 +0100 Subject: [PATCH] Lwt_utils: fix read_mbytes --- src/utils/lwt_utils.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/lwt_utils.ml b/src/utils/lwt_utils.ml index 399045db6..2fcfeaa49 100644 --- a/src/utils/lwt_utils.ml +++ b/src/utils/lwt_utils.ml @@ -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