in reply to non-blocking select with IO::Select

Here are a couple of sugestions. You need to remove the socket from the io::select before you close it. You also need to check the length of what you get from the socket to see if it was closed. Try this code and let me know if it works (I had to guess at some parts).
while (1) { print "yo\n"; while ( my @handles = $self->{daemon}->can_read(1) ) { foreach ( @handles ) { if ($_ == $self->{listener}) { my $new_sock = $self->{listener}->accept or die "accept: $!"; $self->{daemon}->add( $new_sock); } else { my @rawmsg = $_->getlines; if ($rowmsg[0]){ # Or what ever the index of the message is print @rawmsg; } else { $self->{daemon}->remove($_); $_->close; } } } }
Here is some code that I wrote that works with non-blocking and multiple clients.
use IO::Socket; use IO::Select; my $sock = new IO::Socket::INET (LocalHost => '127.0.0.1', LocalPort => 1200, Listen => 5, Proto => 'tcp', Reuse => 1, ) or die $!; my $handles = new IO::Select(); $handles->add($sock); while (1){ print "yo"; my ($s_handles) = IO::Select->select($handles, undef, undef, 1); for my $hndl (@$s_handles){ if ($hndl == $sock){ $handles->add($hndl->accept()); } else { if (my $line = <$hndl>){ print $line; } else { $handles->remove($hndl); close ($hndl); } } } }

Replies are listed 'Best First'.
Socket informaiton from IO::Select?
by natebailey (Acolyte) on Mar 23, 2003 at 08:35 UTC

    The second example is exactly what I was after -- but how can I get information from the sockets? Both 'hndl' and the value returned from '$hndl->accept()' are IO::Socket::INET objects, but neither provide any return values from that object, such as peeraddr or peerhost. How do I know which client it is, in that amorphous group of clients? :-}

    ta, N