aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_tcp.erl
diff options
context:
space:
mode:
authorAli Sabil <[email protected]>2013-03-28 14:46:18 +0100
committerAli Sabil <[email protected]>2013-03-28 14:46:18 +0100
commit6a0b3efb08ab9e367aa2b416555f3c230505bdc2 (patch)
tree081ddfa17b323f41f9cbe0464ed501533c037586 /src/ranch_tcp.erl
parent809a12fdbe5ce355b06bcf197008e1b4e8ea9e21 (diff)
downloadranch-6a0b3efb08ab9e367aa2b416555f3c230505bdc2.tar.gz
ranch-6a0b3efb08ab9e367aa2b416555f3c230505bdc2.tar.bz2
ranch-6a0b3efb08ab9e367aa2b416555f3c230505bdc2.zip
Catch badmatch errors when using file:sendfile
Diffstat (limited to 'src/ranch_tcp.erl')
-rw-r--r--src/ranch_tcp.erl10
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