[erlang-questions] Questions about lib_chan and IRC Lite (other than the one had been asked before).
Gleb Peregud
gleber.p@REDACTED
Wed Jan 14 11:20:15 CET 2009
2009/1/14 lang qiu <qiulang@REDACTED>:
> Hi all,
>
> Nobody replies my question about IRC Lite, so I ask it the second time
> (Change the title in hoping that it may cause some attention). And I notice
> that someone asked about some other questions about IRC Lite before, which
> may suggest this example is tricky.
>
> So my here is my question, if a process sends another process several
> messages in a row while in the receiving process when it processes the first
> message, it does that in its own receiving loop, then all the remaining
> message the first process sends goes into this loop and this may against the
> purpose.
>
> My words may sound nonsense. So check these codes,
>
> In the chat_client.erl,
>
> try_to_connect(Parent, Host, Port, Pwd) ->
> ...
> Parent ! {connected, MM},
> exit(connectorFinished)
> end.
>
> While in parent disconnected/3,
> ...
> receive
> {connected, MM} ->
> lib_chan_mm:send(MM, {login, Group, Nick}),
> wait_login_response(Widget, MM);
> {'EXIT', _Pid, _Reason} -> %% if we add this clause here
> ...
> wait_login_response/2 defines,
> ...
> receive
> ...
> Other ->
> io:format("chat_client login unexpected:~p~p~n",[Other,MM]),
> ...
>
> The result shows that wait_login_response/2 receives try_to_connect's 'EXIT'
> message not disconnected/3. I further test that if try_to_connect sends more
> messages after {connected, MM} , they will all be received by
> wait_login_response instead of disconnected/3 even there are match patterns
> in disconnected/3 (Correct me if I am wrong). But this may not be a good
> idea. Maybe it is better to let disconnected/3 processes the 'EXIT' message
> instead of wait_login_response/2 (because it should only deal with the login
> related message). So how do we fix this problem ? Or I miss something here
> ?
>
> Thanks,
>
> Qiulang
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
You can try alter the code in the following way:
try_to_connect(Parent, Host, Port, Pwd) ->
...
Parent ! {connected, self(), MM},
exit(connectorFinished)
end.
While in parent disconnected/3,
...
receive
{connected, Connector, MM} ->
lib_chan_mm:send(MM, {login, Group, Nick}),
receive {'EXIT', Connector, connectorFinished} -> ok end,
wait_login_response(Widget, MM);
{'EXIT', _Pid, _Reason} -> %% if we add this clause here
...
wait_login_response/2 defines,
...
receive
...
Other ->
io:format("chat_client login unexpected:~p~p~n",[Other,MM]),
...
This change makes parent:disconnected/3 catch 'EXIT' message of
connector at the appropriate moment. Note: I don't know what remaining
code looks like, hence this is based solely on code in your email.
--
Gleb Peregud
http://gleber.pl/
Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong
More information about the erlang-questions
mailing list