25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

* src/ejabberd_socket.erl: Added API for monitoring socket

processes
* src/ejabberd_frontend_socket.erl: Likewise
* src/ejabberd_c2s.erl: Added socket monitoring

* src/mod_muc/mod_muc_room.erl: Fixed the stop reason for the
destroy event

SVN Revision: 751
This commit is contained in:
Alexey Shchepin 2007-04-12 06:08:32 +00:00
parent c65e1e7ae0
commit fa6b6b8f5a
5 changed files with 36 additions and 11 deletions

View File

@ -1,3 +1,13 @@
2007-04-12 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_socket.erl: Added API for monitoring socket
processes
* src/ejabberd_frontend_socket.erl: Likewise
* src/ejabberd_c2s.erl: Added socket monitoring
* src/mod_muc/mod_muc_room.erl: Fixed the stop reason for the
destroy event
2007-04-09 Alexey Shchepin <alexey@sevcom.net> 2007-04-09 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_sm.erl: Minor optimisation * src/ejabberd_sm.erl: Minor optimisation

View File

@ -42,6 +42,7 @@
-record(state, {socket, -record(state, {socket,
sockmod, sockmod,
socket_monitor,
streamid, streamid,
sasl_state, sasl_state,
access, access,
@ -142,16 +143,18 @@ init([{SockMod, Socket}, Opts]) ->
true -> true ->
Socket Socket
end, end,
{ok, wait_for_stream, #state{socket = Socket1, SocketMonitor = SockMod:monitor(Socket1),
sockmod = SockMod, {ok, wait_for_stream, #state{socket = Socket1,
zlib = Zlib, sockmod = SockMod,
tls = TLS, socket_monitor = SocketMonitor,
tls_required = StartTLSRequired, zlib = Zlib,
tls_enabled = TLSEnabled, tls = TLS,
tls_options = TLSOpts, tls_required = StartTLSRequired,
streamid = new_id(), tls_enabled = TLSEnabled,
access = Access, tls_options = TLSOpts,
shaper = Shaper}}. streamid = new_id(),
access = Access,
shaper = Shaper}}.
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
@ -1129,6 +1132,9 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
true -> true ->
{next_state, StateName, NewState} {next_state, StateName, NewState}
end; end;
handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData)
when Monitor == StateData#state.socket_monitor ->
{stop, normal, StateData};
handle_info(Info, StateName, StateData) -> handle_info(Info, StateName, StateData) ->
?ERROR_MSG("Unexpected info: ~p", [Info]), ?ERROR_MSG("Unexpected info: ~p", [Info]),
{next_state, StateName, StateData}. {next_state, StateName, StateData}.

View File

@ -22,6 +22,7 @@
reset_stream/1, reset_stream/1,
send/2, send/2,
change_shaper/2, change_shaper/2,
monitor/1,
get_sockmod/1, get_sockmod/1,
get_peer_certificate/1, get_peer_certificate/1,
get_verify_result/1, get_verify_result/1,
@ -98,6 +99,9 @@ send(FsmRef, Data) ->
change_shaper(FsmRef, Shaper) -> change_shaper(FsmRef, Shaper) ->
gen_server:call(FsmRef, {change_shaper, Shaper}). gen_server:call(FsmRef, {change_shaper, Shaper}).
monitor(FsmRef) ->
erlang:monitor(process, FsmRef).
get_sockmod(FsmRef) -> get_sockmod(FsmRef) ->
gen_server:call(FsmRef, get_sockmod). gen_server:call(FsmRef, get_sockmod).
@ -129,6 +133,7 @@ peername(FsmRef) ->
%% Description: Initiates the server %% Description: Initiates the server
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
init([Module, SockMod, Socket, Opts, Receiver]) -> init([Module, SockMod, Socket, Opts, Receiver]) ->
%% TODO: monitor the receiver
Node = ejabberd_node_groups:get_closest_node(backend), Node = ejabberd_node_groups:get_closest_node(backend),
{ok, Pid} = {ok, Pid} =
rpc:call(Node, Module, start, [{?MODULE, self()}, Opts]), rpc:call(Node, Module, start, [{?MODULE, self()}, Opts]),

View File

@ -19,6 +19,7 @@
reset_stream/1, reset_stream/1,
send/2, send/2,
change_shaper/2, change_shaper/2,
monitor/1,
get_sockmod/1, get_sockmod/1,
get_peer_certificate/1, get_peer_certificate/1,
get_verify_result/1, get_verify_result/1,
@ -120,6 +121,9 @@ send(SocketData, Data) ->
change_shaper(SocketData, Shaper) -> change_shaper(SocketData, Shaper) ->
ejabberd_receiver:change_shaper(SocketData#socket_state.receiver, Shaper). ejabberd_receiver:change_shaper(SocketData#socket_state.receiver, Shaper).
monitor(SocketData) ->
erlang:monitor(process, SocketData#socket_state.receiver).
get_sockmod(SocketData) -> get_sockmod(SocketData) ->
SocketData#socket_state.sockmod. SocketData#socket_state.sockmod.

View File

@ -617,7 +617,7 @@ handle_event({destroy, Reason}, _StateName, StateData) ->
[{xmlelement, "reason", [{xmlelement, "reason",
[], [{xmlcdata, Reason}]}] [], [{xmlcdata, Reason}]}]
end}, StateData), end}, StateData),
{stop, stopped_by_event, StateData}; {stop, normal, StateData};
handle_event(destroy, StateName, StateData) -> handle_event(destroy, StateName, StateData) ->
handle_event({destroy, none}, StateName, StateData); handle_event({destroy, none}, StateName, StateData);