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

Tcpv{4,6}_socket: transform EPIPE into Eof #183

Merged
merged 1 commit into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions unix/tcpv4_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ let read fd =
(fun exn -> return (`Error (`Unknown (Printexc.to_string exn))))

let rec write fd buf =
Lwt_cstruct.write fd buf
>>= function
| n when n = Cstruct.len buf -> return (`Ok ())
| 0 -> return `Eof
| n -> write fd (Cstruct.sub buf n (Cstruct.len buf - n))
Lwt.catch
(fun () ->
Lwt_cstruct.write fd buf
>>= function
| n when n = Cstruct.len buf -> return (`Ok ())
| 0 -> return `Eof
| n -> write fd (Cstruct.sub buf n (Cstruct.len buf - n))
) (function
| Unix.Unix_error(Unix.EPIPE, _, _) -> return `Eof
| e -> Lwt.fail e)

let writev fd bufs =
Lwt_list.fold_left_s
Expand Down
15 changes: 10 additions & 5 deletions unix/tcpv6_socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ let read fd =
(fun exn -> return (`Error (`Unknown (Printexc.to_string exn))))

let rec write fd buf =
Lwt_cstruct.write fd buf
>>= function
| n when n = Cstruct.len buf -> return (`Ok ())
| 0 -> return `Eof
| n -> write fd (Cstruct.sub buf n (Cstruct.len buf - n))
Lwt.catch
(fun () ->
Lwt_cstruct.write fd buf
>>= function
| n when n = Cstruct.len buf -> return (`Ok ())
| 0 -> return `Eof
| n -> write fd (Cstruct.sub buf n (Cstruct.len buf - n))
) (function
| Unix.Unix_error(Unix.EPIPE, _, _) -> return `Eof
| e -> Lwt.fail e)

let writev fd bufs =
Lwt_list.fold_left_s
Expand Down