mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +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_trailer(SocketData) ->
|
||||||
send(SocketData, <<"</stream:stream>">>).
|
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) ->
|
send(#socket_state{sockmod = SockMod, socket = Socket} = SocketData, Data) ->
|
||||||
?DEBUG("(~s) Send XML on stream = ~p", [pp(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 ->
|
catch _:badarg ->
|
||||||
%% Some modules throw badarg exceptions on closed sockets
|
%% Some modules throw badarg exceptions on closed sockets
|
||||||
%% TODO: their code should be improved
|
%% TODO: their code should be improved
|
||||||
{error, einval}
|
{error, closed}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec send_xml(socket_state(),
|
-spec send_xml(socket_state(),
|
||||||
|
@ -1104,6 +1104,8 @@ set_lang(Pkt, _) ->
|
|||||||
Pkt.
|
Pkt.
|
||||||
|
|
||||||
-spec format_inet_error(atom()) -> string().
|
-spec format_inet_error(atom()) -> string().
|
||||||
|
format_inet_error(closed) ->
|
||||||
|
"connection closed";
|
||||||
format_inet_error(Reason) ->
|
format_inet_error(Reason) ->
|
||||||
case inet:format_error(Reason) of
|
case inet:format_error(Reason) of
|
||||||
"unknown POSIX error" -> atom_to_list(Reason);
|
"unknown POSIX error" -> atom_to_list(Reason);
|
||||||
|
@ -764,6 +764,8 @@ select_lang(Lang, <<"">>) -> Lang;
|
|||||||
select_lang(_, Lang) -> Lang.
|
select_lang(_, Lang) -> Lang.
|
||||||
|
|
||||||
-spec format_inet_error(atom()) -> string().
|
-spec format_inet_error(atom()) -> string().
|
||||||
|
format_inet_error(closed) ->
|
||||||
|
"connection closed";
|
||||||
format_inet_error(Reason) ->
|
format_inet_error(Reason) ->
|
||||||
case inet:format_error(Reason) of
|
case inet:format_error(Reason) of
|
||||||
"unknown POSIX error" -> atom_to_list(Reason);
|
"unknown POSIX error" -> atom_to_list(Reason);
|
||||||
|
Loading…
Reference in New Issue
Block a user