P2P: properly handle End_of_file
.
This commit is contained in:
parent
c9fdaf13ec
commit
2a43eeaa7f
@ -203,7 +203,7 @@ module Make (P: PARAMS) = struct
|
||||
| Some msg ->
|
||||
Lwt.return msg)
|
||||
(function
|
||||
| Unix.Unix_error _ -> return Disconnect
|
||||
| Unix.Unix_error _ | End_of_file -> return Disconnect
|
||||
| e -> fail e)
|
||||
|
||||
(* send a message over a TCP socket *)
|
||||
@ -236,7 +236,7 @@ module Make (P: PARAMS) = struct
|
||||
return true
|
||||
end)
|
||||
(function
|
||||
| Unix.Unix_error _ -> return_false
|
||||
| Unix.Unix_error _ | End_of_file -> return_false
|
||||
| e -> fail e)
|
||||
|
||||
(* A peer handle, as a record-encoded object, abstract from the
|
||||
|
@ -231,8 +231,9 @@ let rec read_bytes ?(pos = 0) ?len fd buf =
|
||||
if len = 0 then
|
||||
Lwt.return_unit
|
||||
else
|
||||
Lwt_unix.read fd buf pos len >>= fun nb_read ->
|
||||
inner (pos + nb_read) (len - nb_read)
|
||||
Lwt_unix.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
|
||||
|
||||
@ -254,7 +255,8 @@ let write_mbytes ?(pos=0) ?len descr buf =
|
||||
if len = 0 then
|
||||
Lwt.return_unit
|
||||
else
|
||||
Lwt_bytes.write descr buf pos len >>= fun nb_written ->
|
||||
inner (pos + nb_written) (len - nb_written) in
|
||||
Lwt_bytes.write descr buf pos len >>= function
|
||||
| 0 -> Lwt.fail End_of_file (* other endpoint cleanly closed its connection *)
|
||||
| nb_written -> inner (pos + nb_written) (len - nb_written) in
|
||||
inner pos len
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user