vti/pocketio — pull request #21 by michael-fig (2012-06-12 16:45:00+00:00)
Title: Distributing messages to split connections

Hi,

I've implemented the hooks I need to distribute messages to split connections, and tested them with my custom Pool. I take advantage of the fact that publish/subscribe to my Pools is of low enough latency that I don't need to do special mapping of Connections to Pools.

Here is the Pool logic to use these hooks:

sub new {
# FIXME: Start async task receiving pool messages and
# call PocketIO::Pool to dispatch:
$self->SUPER::send_raw($msg);
}

sub send_raw {
# FIXME: Publish to all pools.
}

sub find_connection {
my $self = shift;
my $conn = $self->find_local_connection(@_);
if (!defined $conn) {
# This connection is split between the reader side (somewhere else),
# and the writer side (here). Create a proxy connection!
($conn) = @_;
my $id = blessed $conn ? $conn->id : $conn;
$conn = PocketIO::Connection->new_passive(id => $id, pool => $self);
$conn->on('write', sub {
my $conn = shift;
my ($bytes) = @_;
$self->send_raw(id => $id, bytes => $bytes);
});
}
}