On Thu, Aug 21, 2003 at 04:12:34PM -0400, Dan McCormick wrote:
> Howdy,
>
> If no one's released a PoCo::Net::OSCAR (i.e. the public face of AOL's
> IM), I've got one to offer.
>
> However, I was hoping for a bit of feedback first, because I'm not sure
> I've gone about it in the best way. The Net::OSCAR module is very nice
> in that it can use other event loops. The only hitch is that it thinks
> in terms of filenos and it looks like POE thinks in terms of sockets and
> handles. I'm not too well-versed in this area, but after a bit of trial
> and error, I came up with this:
>
> # sign on, and set up POE to monitor all the connections
> $_[HEAP]->{oscar}->signon( %args );
[...]
> This works fine, but it seems a bit heavy on the selects. Is there a
> better way?
It looks like Net::OSCAR has a findconn() function that will find a
connection based on a socket's file descriptor. Generating file
descriptors from socket handles is a lot easier than going the other
way: just call fileno() on them.
This code (untested!) simulates Net::OSCAR::process_connections() on one
connection at a time.
The only shame is that Net::OSCAR::findconn() does a grep on all the
connections to find the matching one. A hash of (fileno => connection)
pairs would be nice there.
foreach my $conn (@{ $heap->{oscar}->{connections} }) {
$kernel->select($connection->{socket}, 'rd_ok', 'wr_ok', 'ex_ok');
}
sub rd_ok {
my ($heap, $socket) = @_[HEAP, ARG0];
my $conn = $heap->{oscar}->findconn(fileno($socket));
$conn->process_one(1, 0);
}
sub wr_ok {
my ($heap, $socket) = @_[HEAP, ARG0];
my $conn = $heap->{oscar}->findconn(fileno($socket));
$conn->process_one(0, 1);
}
sub ex_ok {
my ($heap, $socket) = @_[HEAP, ARG0];
my $conn = $heap->{oscar}->findconn(fileno($socket));
$kernel->select($socket); # stop the socket from POE
$connection->{sockerr} = 1;
$connection->disconnect();
}
Good luck.
--
Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/