http://qs321.pair.com?node_id=270472


in reply to Re: 2 problems using sockets perl 5.8 and mod_perl2 on Linux
in thread 2 problems using sockets perl 5.8 and mod_perl2 on Linux


Hello,

Okay, I grok this and removed the
if ($!) { print STDERR "ERROR $!\n"; }
I don't understand why even without checking this the loop spins uncontrolably until it times out (notice the use of Time::HiRes).

What I am observing as that this select loop keeps returning, $nf is set to 1, but there is no file descriptor in $eout, nor in $rout set to 1 and the loop just starts over again. This chomps up CPU and degrades the performance so badly I can't use it for it's intended purpose.

Is the logic I am using to detect readable or erroring file descriptors perhaps incorrect?

Thanks -- rr

Replies are listed 'Best First'.
Re: Re: Re: 2 problems using sockets perl 5.8 and mod_perl2 on Linux
by Thelonius (Priest) on Jul 03, 2003 at 03:05 UTC
    After much pondering, I think the problem is that you are initializing your bit vectors like this:
    my $rin = 0;
    but you should be doing this
    my $rin = '';
    When you say: $rin = 0; vec($rin, $fd, 1) = 1;, apparently the 0 is converted to the string "0" before the bit for $fd is set. This means that an extra bit will be set in each of your vectors.

    Personally, I've never understood vec() well enough to want to use it. I always use IO::Select and can_read() rather than that. I highly recommend the IO::Socket and IO::Select methods because they are so easy to use and, I think, less error-prone.