mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Return 'closed' instead of 'einval' on closed sockets
This commit is contained in:
parent
0822108fc8
commit
071c1dcb64
@ -211,14 +211,16 @@ send_trailer(SocketData) when ?is_http_socket(SocketData) ->
|
||||
send_trailer(SocketData) ->
|
||||
send(SocketData, <<"</stream:stream>">>).
|
||||
|
||||
-spec send(socket_state(), iodata()) -> ok | {error, inet:posix()}.
|
||||
-spec send(socket_state(), iodata()) -> ok | {error, closed | inet:posix()}.
|
||||
send(#socket_state{sockmod = SockMod, socket = Socket} = SocketData, Data) ->
|
||||
?DEBUG("(~s) Send XML on stream = ~p", [pp(SocketData), Data]),
|
||||
try SockMod:send(Socket, Data)
|
||||
try SockMod:send(Socket, Data) of
|
||||
{error, einval} -> {error, closed};
|
||||
Result -> Result
|
||||
catch _:badarg ->
|
||||
%% Some modules throw badarg exceptions on closed sockets
|
||||
%% TODO: their code should be improved
|
||||
{error, einval}
|
||||
{error, closed}
|
||||
end.
|
||||
|
||||
-spec send_xml(socket_state(),
|
||||
|
@ -1104,6 +1104,8 @@ set_lang(Pkt, _) ->
|
||||
Pkt.
|
||||
|
||||
-spec format_inet_error(atom()) -> string().
|
||||
format_inet_error(closed) ->
|
||||
"connection closed";
|
||||
format_inet_error(Reason) ->
|
||||
case inet:format_error(Reason) of
|
||||
"unknown POSIX error" -> atom_to_list(Reason);
|
||||
|
@ -764,6 +764,8 @@ select_lang(Lang, <<"">>) -> Lang;
|
||||
select_lang(_, Lang) -> Lang.
|
||||
|
||||
-spec format_inet_error(atom()) -> string().
|
||||
format_inet_error(closed) ->
|
||||
"connection closed";
|
||||
format_inet_error(Reason) ->
|
||||
case inet:format_error(Reason) of
|
||||
"unknown POSIX error" -> atom_to_list(Reason);
|
||||
|
Loading…
Reference in New Issue
Block a user