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);
}
}
}
}