aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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