What is Megaphone?

What is Megaphone?
The Megaphone project is about enhancing open source chat software. Specifically, the goal is to allow ejabberd to support 1,000,000 simultaneous users. See The Plan page for more details on how I plan to solve this problem. See the About this Blog page for more details on why I created this blog.

Tuesday, January 10, 2012

Why Is It That...

Previously...
  • I identified a problem where data was going into ejabberd_http but not coming out.
  • I discovered that ejabberd_http was expecting parsed data.
  • I discovered that gen_tcp could partially parse HTTP.

After my little discovery that gen_tcp could indeed parse some HTTP and that consequently megaphone would have to do some HTTP parsing I looked into ways that this could be accomplished.  One thing that jumped out at me was that I could use erlang:decode_packet to do all the hard work for me - outstanding!

So I set about looking into my code to make the changes and came across the following:

receive_loop (Socket, State, Old) ->
    case gen_tcp:recv(Socket, 0) of
        { ok, Binary } ->
            Data = binary_to_list(Binary),
            Leftovers = process_loop(Old, Data),
            receive_loop(Socket, State, Leftovers);


"Ha Ha!" I thought, "I can just grab the header off, decode that and then run erlang:decode_packet on the rest and everything will be great!"

So I revised this fragment to the following:

receive_loop (Socket, State, Old) ->
    case gen_tcp:recv(Socket, 0) of
        { ok, Binary } ->
            Data = binary_to_list(Binary),
            HeaderPart = binary_part(Binary, 0, 33),
            Leftovers = process_loop(Old, Data),
            receive_loop(Socket, State, Leftovers);

I tried this and promptly got my old friend of an error:

=ERROR REPORT==== 2012-01-10 08:20:05 ===
C(<0.37.0>:gen_mod:76) : Problem starting the module mod_adhoc for host "ubuntu2" 
 options: []
 exit: {noproc,
           {gen_server,call,
               [ejabberd_iq_sup,
                {start_child,["ubuntu2",mod_adhoc,process_local_iq]},
                infinity]}}

This was happened before when I was missing a function declaration, but I still don't know why it was happening.  The work-around before was to simply define the function that I was missing, but this time I actually need the code that I am missing.

Anyone know what is causing this?  You'll get a reward in the form of good karma...or dogma...or whatever...

No comments:

Post a Comment