Ok... so we use FCGI, and I hate it, since when we have problems I can't track them down. SO... I am writing a perl version. Not that that is terribly important.

What is important is that I have a server process, which manages multiple children listening to the same socket. To keep track of these children and decide if I need to fork more or reap a few, I have two way pipes that talk to a master process, saying when they get a call and when they are done with a call.

My problem is that I have all the child read pipes in IO::Select, and occasionally (easy to duplicate if the waiting message quickly follows the call message) I lose the waiting message. Basically I have one line messages, so can_read returns, I get the 'call' message, then I return. The 'waiting' message may already be there, but I leave that for the next cycle for can_read to pick up again. However, it doesn't always get picked up.

Any ideas? Am I going about this the wrong way? I tested and found the 'waiting' message was actually there. I had assumed that if I didn't read everything from the socket that can_read would return true until there was nothing left to read... am I wrong. Or am I possibly not using the proper read method? Maybe perl is doing some weird buffering when I use $msg = scalar <$cr>; ?

Of course, if anyone has suggestions on how better to track when the children are in a call I'm open to that, too... I don't know if there is any way to tell how many children are listening on a socket or something similar.

Below is a snippet of the code:

for(0..1) { my @ready = $self->{root}{select}->can_read(0); for(@ready) { $self->handle_child_message($self->{root}{childreads}{$_},$_); } } sub handle_child_message { my $self = shift; my $child = shift; my $cr = shift; my $msg = <$cr>; if($msg =~ /^call/) { $self->{root}{busy}{$child} = 1; $self->{root}{busycount}++; $self->{root}{children}{$child}{calls}++; } elsif($msg =~ /^waiting/) { $self->{root}{busycount}-- if delete $self->{root}{busy}{$chil +d}; } }

                - Ant
                - Some of my best work - (1 2 3)


In reply to IO::Select can_read missing some reads... by suaveant

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.