Index: src/ejabberd_ircd.erl
===================================================================
--- src/ejabberd_ircd.erl (revision 107)
+++ src/ejabberd_ircd.erl (working copy)
@@ -7,6 +7,7 @@
%% External exports
-export([start/2,
start_link/2,
+ become_controller/1,
socket_type/0]).
%% gen_fsm callbacks
@@ -20,7 +21,7 @@
terminate/3
]).
-%-define(ejabberd_debug, true).
+-define(ejabberd_debug, true).
-include("ejabberd.hrl").
-include("jlib.hrl").
@@ -51,7 +52,7 @@
-record(line, {prefix, command, params}).
-%-define(DBGFSM, true).
+-define(DBGFSM, true).
-ifdef(DBGFSM).
-define(FSMOPTS, [{debug, [trace]}]).
@@ -71,6 +72,9 @@
socket_type() ->
raw.
+become_controller(Pid) ->
+ gen_fsm:send_all_state_event(Pid, become_controller).
+
%%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm
%%%----------------------------------------------------------------------
@@ -119,7 +123,7 @@
?DICT:store(RoomJID, BareChannel, JToC)}
end, {?DICT:new(), ?DICT:new()},
ChannelMappings),
- inet:setopts(Socket, [list, {packet, line}, {active, true}]),
+ %%inet:setopts(Socket, [list, {packet, line}, {active, true}]),
%%_ReceiverPid = start_ircd_receiver(Socket, SockMod),
{ok, wait_for_nick, #state{socket = Socket,
sockmod = SockMod,
@@ -149,6 +153,9 @@
Reply = ok,
{reply, Reply, StateName, StateData}.
+handle_event(become_controller, StateName, StateData) ->
+ activate_socket(StateData),
+ {next_state, StateName, StateData};
handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}.
@@ -836,3 +843,11 @@
end;
error_to_string(_) ->
"unknown error".
+
+activate_socket(#state{socket = Socket, sockmod = SockMod}) ->
+ case SockMod of
+ gen_tcp ->
+ inet:setopts(Socket, [list, {packet, line}, {active, true}]);
+ _ ->
+ SockMod:setopts(Socket, [list, {packet, line}, {active, once}])
+ end.