[erlang-questions] Strange error with client/server IRC code

Berlin Brown berlin.brown@REDACTED
Thu Feb 28 02:00:32 CET 2008


On Wed, Feb 27, 2008 at 3:09 PM, bbrown <bbrown@REDACTED> wrote:
> This is some IRC code (this is your code orbitz if you are on); that whenever
>  when I call these type methods I get an error.  I dont have the error so this
>  post might be a little worthless right now; I am on a different environment
>  and going by memory.  But, basically the error is with the handle_cast
>  function.  It looks like it is not reaching any of the "handle_cast" calls.
>  How do those work.  Sorry, when I get home, I will provide a little bit more
>  information.
>
>  ----
>     send_client_command(Irclib, "JOIN", [Channel, Pass]);
>  join(Irclib, Channel) when list(Channel) ->
>         io:format("trace: join@~p~n", [Channel]),
>         %% TODO: remove test code
>     send_client_command(Irclib, "JOIN").
>
>  -----
>
>  handle_cast(irc_connect, #state{client=Client, state=disconn} = State) ->
>     {ok, Sock} = connect_to_next_server(Client),
>     {noreply, State#state{sock=Sock, state=connecting}};
>  handle_cast({irc_send_command, {"PING"}}, #state{sock=Sock, client=Client} =
>  State) ->
>     send_command(Sock, {"PING", [dict_proc:fetch(nick, Client)]}),
>     {noreply, State};
>  handle_cast({irc_send_command, {"NICK", [Nick]}}, #state{sock=Sock,
>  client=Client} = State) ->
>     send_command(Sock, {"NICK", [Nick]}),
>     dict_proc:store(nick, Nick, Client),
>     {noreply, State};
>  handle_cast({irc_send_command, Command}, #state{sock=Sock} = State) ->
>         io:format("trace: handle_cast"),
>     send_command(Sock, Command),
>     {noreply, State}.
>
>  send_client_command(Irclib, Command, Args) ->
>         io:format("trace: irc_lib.invoke cast(1) {{ ~p ~p }}~n", [Command, Args]),
>     gen_server:cast(Irclib, {irc_send_command, {Command, Args}}).
>
>  send_client_command(Irclib, Command) ->
>         io:format("trace: irc_lib.invoke cast(2)"),
>     gen_server:cast(Irclib, {irc_send_command, {Command}}).
>
>  % Functions used to send various command sto the client
>  pong(Irclib, Server) ->
>     send_client_command(Irclib, "PONG", [Server]).
>
>  ping(Irclib) ->
>     send_client_command(Irclib, "PING").
>
>  whois(Irclib, Who) ->
>     send_client_command(Irclib, "WHOIS", [Who]).
>
>  join(Irclib, {Channel, Pass}) ->
>         io:format("trace: join(a)@~p~n", [Channel]),
>     send_client_command(Irclib, "JOIN", [Channel, Pass]);
>  join(Irclib, Channel) when list(Channel) ->
>         io:format("trace: join@~p~n", [Channel]),
>         %% TODO: remove test code
>     send_client_command(Irclib, "JOIN").
>
>
>  http://openbotlist.googlecode.com/svn/trunk/botlistprojects/laughingman/orbirclib/src/irc_lib.erl
>
>
>
>  --
>  Berlin Brown
>  email: berlin-dot-brown-AT-gmail-dot-com
>  http://botspiritcompany.com/botlist/
>
>

Sorry, I am at my machine now:

I get this error

trace: irc_lib.invoke cast(2){"init terminating in
do_boot",{function_clause,[{gen_server,cast,[{ok,<0.29.0>},{irc_send_command,{"JOIN"}}]},{simple_irc_lib,test,0},{init,start_it,1},{init,start_em,1}]}}

Here is my test case and some of my function tracing:

This is the call:
------

   P = irc_lib:start_link(#irc_client_info{realname="foo",
											nick="ort_test",
											handler=self(),
											servers=[{"irc.freenode.org", 6667}]}),
	io:format("irc_lib:start_link ->~p ~n", [P]),
	timer:sleep(18000),
	irc_lib:join(P, "erlang"),
	timer:sleep(10000),

The error is at irc_lib:join:


join(Irclib, {Channel, Pass}) ->
	io:format("trace: join(a)@~p~n", [Channel]),
    send_client_command(Irclib, "JOIN", [Channel, Pass]);
join(Irclib, Channel) when list(Channel) ->
	io:format("trace: join@~p~n", [Channel]),
	%% TODO: remove test code
    send_client_command(Irclib, "JOIN").
------

And then:

send_client_command(Irclib, Command, Args) ->
	io:format("trace: irc_lib.invoke cast(1) {{ ~p ~p }}~n", [Command, Args]),
    gen_server:cast(Irclib, {irc_send_command, {Command, Args}}).

send_client_command(Irclib, Command) ->
	io:format("trace: irc_lib.invoke cast(2)"),
    gen_server:cast(Irclib, {irc_send_command, {Command}}).

---------

I am assuming that it should get here, but it isn't.  My code doesn't
get to this point.

handle_cast({irc_send_command, Command}, #state{sock=Sock} = State) ->
	io:format("trace: handle_cast"),
    send_command(Sock, Command),
    {noreply, State}.
-------------------

Here is the full call of that library:
http://openbotlist.googlecode.com/svn/trunk/botlistprojects/laughingman/orbirclib/src/irc_lib.erl

And thanks to orbitz for the code and library.
---
Berlin Brown
http://botspiritcompany.com/botlist/spring/help/about.html



More information about the erlang-questions mailing list