Skip to content

Commit

Permalink
Merge pull request #183 from djs55/catch_epipe
Browse files Browse the repository at this point in the history
Tcpv{4,6}_socket: transform EPIPE into Eof
  • Loading branch information
avsm committed Mar 19, 2016
2 parents 8d43cc1 + 002812c commit 1b1bdd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
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

0 comments on commit 1b1bdd9

Please sign in to comment.