[erlang-questions] Which part of parent process should receive 'EXIT' message when child process exit(reason) after sending parent a normal message ?

lang qiu qiulang@REDACTED
Mon Jan 12 17:16:31 CET 2009


Hi all,

The IRC Lite example in "programming erlang" makes me think some question
that I thought I have understood.

1. Which part of parent process should receive 'EXIT' message when child
process exit(reason) after sending parent a normal message ?
So in the chat_client.erl,

try_to_connect(Parent, Host, Port, Pwd) ->
        ...
        Parent ! {*connected, MM*},
        exit(*connectorFinished*)
    end.

While in parents *disconnected/3*,
...
    receive
    {*connected, MM*} ->
        ...
        *wait_login_response*(Widget, MM);
     {*'EXIT', _Pid, _Reason*} -> %% if we add this clause here
...
*wait_login_response/2* defines,
...
     receive
     { {*'EXIT', _Pid, _Reason*}  -> %% it actually just define Other -> ...
...

The result shows that wait_login_response/2 receives the '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). So for a general cases, is this a good idea
(design) to make the first message match part receives the remaining
messages after the first match (if the first match part has its own receive
loop) instead of the other part of receiving function ? Or I miss something
here ?

2. Why mod_chat_controller *only *receives login message ? After all,
chat_client uses lib_chan_mm:send(MM) for both login and relay messages ?

3. When I close a window, except for the expected message "I'm leaving the
group", the server also output the error message "server error should die
with exit(normal) was:{mm_closed,<xxx>}". Why does this happen and how to
fix it ?

Thanks!

Qiulang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090113/c0a26c3d/attachment.htm>


More information about the erlang-questions mailing list