suaveant has asked for the wisdom of the Perl Monks concerning the following question:
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: IO::Select can_read missing some reads...
by merlyn (Sage) on Mar 13, 2002 at 16:57 UTC | |
by suaveant (Parson) on Mar 13, 2002 at 18:35 UTC | |
|
Re: IO::Select can_read missing some reads...
by jeffenstein (Hermit) on Mar 13, 2002 at 18:32 UTC | |
by suaveant (Parson) on Mar 13, 2002 at 18:40 UTC | |
|
Re: IO::Select can_read missing some reads...
by Rex(Wrecks) (Curate) on Mar 13, 2002 at 18:33 UTC |