- My primary computer's power supply died.
- I salvaged one of the drives from my dead computer.
- I discovered a problem in the receive logic.
Some reading from http://www.erlang.org/doc/man/erlang.htm turned up the following information about the decode_packet function:
If Bin does not contain the entire packet, {more,Length} is returned. Length is either the expected total size of the packet or undefined if the expected packet size is not known. decode_packet can then be called again with more data added.
The problem is that the megaphone function expects to receive a complete packet when it is sent the put_data message. This means that the megaphone_receiver process needs to change.
The relevant function in the megaphone_receiver module is:
receive_loop (Socket, _OldState, LeftOvers) ->
case gen_tcp:recv(Socket, 0) of
{ ok, Binary } ->
{ PacketLength, ConnectionID, Data } = receive_header(Socket, LeftOvers, Binary),
{ Packet, NewLeftOvers } = receive_packet_body (Socket, Data, PacketLength - ?HEADER_LENGTH),
{ IntConnectionID, _Rest } = string:to_integer(ConnectionID),
give_packet_to_megaphone (IntConnectionID, Packet),
receive_loop(Socket, undefined, NewLeftOvers);
_Other ->
gen_tcp:close(Socket)
end.
The odd thing is that the whole point of the receive_packet_body function is to deal with partial packets and the like. After putting in some debugging statements I came to the realization that megaphone is not, as a point of fact, receiving HTTP requests --- it is receiving the body of those requests.
This is one of those "uh oh" moments --- BOSH expects to get a reply to each request within a certain timeout period, regardless of whether there is any data for it. I was hoping to foist all that logic onto ejabberd's BOSH module, but I can't do that if megaphone is receiving packet bodies instead of whole HTTP requests.
Therefore, I either need to go back to ECM and change it to forward the raw TCP data, or I need to change megaphone to expect packet bodies and ECM needs to watch out for timeouts.
More decisions.
Next time: which way to go with this decision.
No comments:
Post a Comment