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

In reply to Re: non-blocking select with IO::Select by c-era
in thread non-blocking select with IO::Select by dash2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.