diff --git a/ChangeLog b/ChangeLog index bb69000da..8324db941 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-04-12 Alexey Shchepin + + * 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 * src/ejabberd_sm.erl: Minor optimisation diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index f1c3dddfc..bf4a3ac05 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -42,6 +42,7 @@ -record(state, {socket, sockmod, + socket_monitor, streamid, sasl_state, access, @@ -142,16 +143,18 @@ init([{SockMod, Socket}, Opts]) -> true -> Socket end, - {ok, wait_for_stream, #state{socket = Socket1, - sockmod = SockMod, - zlib = Zlib, - tls = TLS, - tls_required = StartTLSRequired, - tls_enabled = TLSEnabled, - tls_options = TLSOpts, - streamid = new_id(), - access = Access, - shaper = Shaper}}. + SocketMonitor = SockMod:monitor(Socket1), + {ok, wait_for_stream, #state{socket = Socket1, + sockmod = SockMod, + socket_monitor = SocketMonitor, + zlib = Zlib, + tls = TLS, + tls_required = StartTLSRequired, + tls_enabled = TLSEnabled, + tls_options = TLSOpts, + streamid = new_id(), + access = Access, + shaper = Shaper}}. %%---------------------------------------------------------------------- @@ -1129,6 +1132,9 @@ handle_info({route, From, To, Packet}, StateName, StateData) -> true -> {next_state, StateName, NewState} end; +handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData) + when Monitor == StateData#state.socket_monitor -> + {stop, normal, StateData}; handle_info(Info, StateName, StateData) -> ?ERROR_MSG("Unexpected info: ~p", [Info]), {next_state, StateName, StateData}. diff --git a/src/ejabberd_frontend_socket.erl b/src/ejabberd_frontend_socket.erl index a906f1912..09f75dfdc 100644 --- a/src/ejabberd_frontend_socket.erl +++ b/src/ejabberd_frontend_socket.erl @@ -22,6 +22,7 @@ reset_stream/1, send/2, change_shaper/2, + monitor/1, get_sockmod/1, get_peer_certificate/1, get_verify_result/1, @@ -98,6 +99,9 @@ send(FsmRef, Data) -> change_shaper(FsmRef, Shaper) -> gen_server:call(FsmRef, {change_shaper, Shaper}). +monitor(FsmRef) -> + erlang:monitor(process, FsmRef). + get_sockmod(FsmRef) -> gen_server:call(FsmRef, get_sockmod). @@ -129,6 +133,7 @@ peername(FsmRef) -> %% Description: Initiates the server %%-------------------------------------------------------------------- init([Module, SockMod, Socket, Opts, Receiver]) -> + %% TODO: monitor the receiver Node = ejabberd_node_groups:get_closest_node(backend), {ok, Pid} = rpc:call(Node, Module, start, [{?MODULE, self()}, Opts]), diff --git a/src/ejabberd_socket.erl b/src/ejabberd_socket.erl index 61040bf53..884483d56 100644 --- a/src/ejabberd_socket.erl +++ b/src/ejabberd_socket.erl @@ -19,6 +19,7 @@ reset_stream/1, send/2, change_shaper/2, + monitor/1, get_sockmod/1, get_peer_certificate/1, get_verify_result/1, @@ -120,6 +121,9 @@ send(SocketData, Data) -> change_shaper(SocketData, Shaper) -> ejabberd_receiver:change_shaper(SocketData#socket_state.receiver, Shaper). +monitor(SocketData) -> + erlang:monitor(process, SocketData#socket_state.receiver). + get_sockmod(SocketData) -> SocketData#socket_state.sockmod. diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index 6c7d06105..3056c510b 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -617,7 +617,7 @@ handle_event({destroy, Reason}, _StateName, StateData) -> [{xmlelement, "reason", [], [{xmlcdata, Reason}]}] end}, StateData), - {stop, stopped_by_event, StateData}; + {stop, normal, StateData}; handle_event(destroy, StateName, StateData) -> handle_event({destroy, none}, StateName, StateData);