- I finished the receiver.
- I created the sender.
- I started planning the megaphone module.
The main megaphone module, aside from being a phrase that has 3 words that start with the letter "m" and being difficult to say quickly, sits in a process by itself and mostly deals with incoming data.
The basic problem is that there is no way I know of to both wait for data on a TCP socket while simultaneously waiting for an erlang message. Clients want to wait for new data to arrive on the TCP socket that is bound for the virtual connection. Those clients also want the data to be parsed out into chunks that one would get from erlang:receive_packet in http mode. Thus clients have the following loop:
- Get the next HTTP header or body, waiting if necessary.
- Do something with the result.
A straight-forward way of solving this problem is to create a new process that waits for the next segment from the TCP connection and then have it notify any erlang processes that are waiting for data for the corresponding virtual connection. In order to do this, the TCP waiter needs to know which processes are waiting for data from a given virtual connection.
That problem can be solved by having the TCP waiter wait for erlang messages that contain the erlang PID of the process that is interested in new data for each virtual connection. The server process simply waits in a loop for messages that contain registration requests. This requires that the TCP waiter also wait for erlang messages, which I don't know how to do.
The solution I came up with is to have the TCP waiter in one process, called megaphone_receiver, and the function that registers clients that want data for a virtual connection in another process, called the megaphone process. I admit that this is a somewhat cumbersome process, so I'm hoping that one of the many readers of this blog will comment on this post with a more elegant solution.
So go ahead and write in.
Any time now.
Well, while I'm waiting I'll just start coding this up...
No comments:
Post a Comment