diff options
author | Loïc Hoguin <[email protected]> | 2013-04-02 14:11:35 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-04-02 14:11:35 +0200 |
commit | ce81cca5c834b0671af5c40e29462823997f445e (patch) | |
tree | 484865b280daf5020c19a6a57fc44846f2d62ee0 | |
parent | 0343f96bb9d2d7b8247a8a183620ccef8a79c26b (diff) | |
parent | 6a0b3efb08ab9e367aa2b416555f3c230505bdc2 (diff) | |
download | ranch-ce81cca5c834b0671af5c40e29462823997f445e.tar.gz ranch-ce81cca5c834b0671af5c40e29462823997f445e.tar.bz2 ranch-ce81cca5c834b0671af5c40e29462823997f445e.zip |
Merge branch 'fix/sendfile-badmatch' of git://github.com/soundrop/ranch
-rw-r--r-- | src/ranch_tcp.erl | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/ranch_tcp.erl b/src/ranch_tcp.erl index bb7ad55..b54ae70 100644 --- a/src/ranch_tcp.erl +++ b/src/ranch_tcp.erl @@ -114,7 +114,15 @@ send(Socket, Packet) -> -spec sendfile(inet:socket(), file:name()) -> {ok, non_neg_integer()} | {error, atom()}. sendfile(Socket, Filename) -> - file:sendfile(Filename, Socket). + try file:sendfile(Filename, Socket) of + Result -> Result + catch + error:{badmatch, {error, enotconn}} -> + %% file:sendfile/2 might fail by throwing a {badmatch, {error, enotconn}} + %% this is because its internal implementation fails with a badmatch in + %% prim_file:sendfile/10 if the socket is not connected. + {error, closed} + end. %% @doc Set options on the given socket. %% @see inet:setopts/2 |