On Mon, Apr 25, 2005 at 05:29:34PM +0100, Nick Williams wrote:
>
> Why might you be trying to send data when not connected? Well, the issue
> is that the connection might die/be reset by the app in which case the
> state engine will probably transition to 'reconnect' which will switch
> the {server} back into a SocketFactory. There might still be events
> waiting to fire (e.g. delays) which will with a bit of bad luck end up
> firing while {server} is a SocketFactory and not the ReadWrite wheel.
>
> Now, I could change my code to check the isa() of the server wheel in
> all the callbacks, but it seems like a bit of a hack that I have to code
> defensively around the wheel changing underneath me.
>
> Is there a better way of doing this?
POE::Component::IRC buffers commands and messages sent to a server
while it's reconnecting. The TCP client component could do the same.
I can think of a couple ways to do this. There are probably others.
1. Use a second heap slot for the SocketFactory, and put a buffering
pseudo-wheel in $heap->{server} while the client is disconnected.
Transfer the pseudo-wheel's put() buffer to the Wheel::ReadWrite after
a connection is made.
2. Use a "put" message, and do the buffering internal to Client::TCP:
$kernel->yield(put => "text");
This will add new latency to outgoing messages, and it will conflict
with $heap->{wheel}->put() in the same ways that mixing buffered and
unbuffered I/O do.
--
Rocco Caputo - http://poe.perl.org/