# Check client streams, close any in error

I don't think that is what $eout indicates. I know BrowserUK said:

The 4-arg select is defined as select RBITS,WBITS,EBITS,TIMEOUT where EBITS are those streams in your select group that have experienced error conditions.

but that is not my understanding of $eout. As far as I can tell, $eout indicates file handles with urgent data--not filehandles that have experienced an IO error. In other words, 'exceptional conditions' does not mean 'exceptions'.

5) You're right, I wasn't depopulating $fin (now $rin, to match standard), but at the top of the loop I reinitialized $fin and then set it up again by adding the listening socket and all currently open sockets. That should have taken care of initializing it correctly each time I get to the select.

You're right, I missed that. I chopped out that part of your code to fit it into my example. I'll have to add that back in and see if I can track down what's going on.

I also worked up an example using IO::Socket and I0::Select, which allows you to dispense with all the bit twiddling (which I loathe). The server code is greatly simplified:

#SERVER: use strict; use warnings; use 5.010; use IO::Socket; use IO::Select; my $LISTEN_SOCK = IO::Socket::INET->new( LocalPort => 12555, Listen => 5, Reuse => 1, ) or die "Couldn't create socket: $@"; my $sock_group = IO::Select->new() or die "Couldn't create select"; $sock_group->add($LISTEN_SOCK); warn "listening for connections...\n"; while (1) { my @ready_to_read = $sock_group->can_read; for my $READABLE_SOCK (@ready_to_read) { if ($READABLE_SOCK eq $LISTEN_SOCK) { my $NEW_CONNECTION = $LISTEN_SOCK->accept() or warn "Couldn't connect: $!"; if($NEW_CONNECTION) { $sock_group->add($NEW_CONNECTION); } } else { my $status = $READABLE_SOCK->sysread( my($available_data), + 8096 ); if ($status > 0) { #read some data STDOUT->syswrite($available_data); } elsif ($status == 0) { #read eof=>client closed socket $sock_group->remove($READABLE_SOCK); close $READABLE_SOCK; } else { #undef=>IO error warn "IO error while reading socket: $READABLE_SOCK"; } } } }
#CLIENT: (same as previous)

In reply to Re: socket select hangs after client restarts by 7stud
in thread socket select hangs after client restarts by planetjeff

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.