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

Hello,

I checked and $nf is set to 1 on my machine. Odd.

I also added code to count the number of times this occurs and it happens thousands of times.

I don't think you understood what sgifford said. When $nf is 1, there is no error. This is exactly what should be expected. You only look at $! to see what the error is after there is an error. The perl variable $! and the related C variable errno do not get reset to 0 when there is a successfull call. They will hold the previous error value until another error happens or the program specificly sets them. The moral is: Don't look at $! to see if there has been an error. Only look at it to see what error occurred after something else indicates that there has indeed been an error.

Replies are listed 'Best First'.
Re: Re: 2 problems using sockets perl 5.8 and mod_perl2 on Linux
by rr (Sexton) on Jul 01, 2003 at 14:02 UTC

    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

      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.