Still learning! Erlang Question
Jeff Crane
jefcrane@REDACTED
Sat May 20 21:42:11 CEST 2006
I'm using a ton of debugging trying to keep track of
where there are problems, as I slowly grow my app. I'm
stumped as to why my Handler/1 always seems to output
my debug messages, then jump back to loop/2
All received messages, even for "connected" processes
are being processed by loop, when the connected ones
should be processed by Handler =/
loop(Users, N) ->
%%io:format(" test_server:loop running as PID
:~p~n",[self()]),
receive
{connect, Pid, User, Password} ->
io:format(" test_server:connection request from:~p
~p ~p~n",[Pid, User, Password]),
case member({User, Password}, Users) of
true ->
io:format(" test_server:connection request
approved~n"),
Max = max_connections(),
if
N > Max ->
Pid ! {test_server,{error,
too_many_connections}},
loop(Users, N);
true ->
io:format(" test_server:connection request
approved, new connection/handler!~n"),
New = spawn_link(?MODULE, handler, [Pid]),
Pid ! {test_server, {ok, New}},
loop(Users, N + 1)
end;
false ->
io:format(" test_server:connection request
denied~n"),
Pid ! {test_server, {error, rejected}},
loop(Users, N)
end;
Any ->
case (Any == exit) of
true->
io:format(" test_server PID ~p dying now...~n",
[self()]),
true;
false->
io:format(" test_server Any: received:
~p~n",[Any]),
loop(Users, N)
end
end.
%%io:format(" function loop() dying :
~p~n",[self()]).
handler(Pid) ->
io:format(" test_server:handler on:~p~n",[self()]),
io:format(" test_server:handling:~p~n",[Pid]),
receive
{Pid, quit} ->
io:format("got (quit):~p ~p~n",[Pid, quit]),
Pid ! {test_server, ok};
{Pid, Op} ->
io:format("got:~p ~p~n",[Pid, Op]),
Pid ! {test_server, do_op(Op)},
handler(Pid)
end,
io:format(" function handler() dying : ~p~n",[self()]).
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the erlang-questions
mailing list