25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Merged from trunk SVN r2671:

Support gen_tcp send timeout: Close the connection if the other end has disconnected ungracefully or cannot keep up with the rate at which we are sending data (EJAB-926)

SVN Revision: 2681
This commit is contained in:
Badlop 2009-10-19 14:53:21 +00:00
parent 227514c20c
commit 372658d299
4 changed files with 31 additions and 8 deletions

View File

@ -133,6 +133,7 @@ init_tcp(PortIP, Module, Opts, SockOpts, Port, IPS) ->
{reuseaddr, true},
{nodelay, true},
{send_timeout, ?TCP_SEND_TIMEOUT},
{send_timeout_close, true},
{keepalive, true} |
SockOpts]),
case Res of

View File

@ -260,6 +260,7 @@ open_socket2(Type, Addr, Port) ->
case (catch ejabberd_socket:connect(Addr, Port,
[binary, {packet, 0},
{send_timeout, ?TCP_SEND_TIMEOUT},
{send_timeout_close, true},
{active, false}, Type],
Timeout)) of
{ok, _Socket} = R -> R;

View File

@ -46,6 +46,8 @@
close/1,
sockname/1, peername/1]).
-include("ejabberd.hrl").
-record(socket_state, {sockmod, socket, receiver}).
%%====================================================================
@ -158,10 +160,22 @@ reset_stream(SocketData) when is_atom(SocketData#socket_state.receiver) ->
(SocketData#socket_state.receiver):reset_stream(
SocketData#socket_state.socket).
%% sockmod=gen_tcp|tls|ejabberd_zlib
send(SocketData, Data) ->
catch (SocketData#socket_state.sockmod):send(
SocketData#socket_state.socket, Data).
case catch (SocketData#socket_state.sockmod):send(
SocketData#socket_state.socket, Data) of
ok -> ok;
{error, timeout} ->
?INFO_MSG("Timeout on ~p:send",[SocketData#socket_state.sockmod]),
exit(normal);
Error ->
?DEBUG("Error in ~p:send: ~p",[SocketData#socket_state.sockmod, Error]),
exit(normal)
end.
%% Can only be called when in c2s StateData#state.xml_socket is true
%% This function is used for HTTP bind
%% sockmod=ejabberd_http_poll|ejabberd_http_bind or any custom module
send_xml(SocketData, Data) ->
catch (SocketData#socket_state.sockmod):send_xml(
SocketData#socket_state.socket, Data).

View File

@ -147,8 +147,15 @@ socket_type() ->
raw.
send_text(State, Text) ->
(State#state.sockmod):send(State#state.socket, Text).
case catch (State#state.sockmod):send(State#state.socket, Text) of
ok -> ok;
{error, timeout} ->
?INFO_MSG("Timeout on ~p:send",[State#state.sockmod]),
exit(normal);
Error ->
?DEBUG("Error in ~p:send: ~p",[State#state.sockmod, Error]),
exit(normal)
end.
receive_headers(State) ->
SockMod = State#state.sockmod,