Hello,

I am experiencing 2 problems with Perl 5.8 under mod_perl2 (apache 2) on Linux (Mandrake 9.1). Included is the subroutine and some example code to use it that can be used to replicate the problems.

Problem 1: When the program below is run, the program spits out "ERROR Bad file descriptor". There is no good reason for this. If I run the same code in the debugger it works correctly. I don't get it, I think this is a bug.

Problem 2: The subroutine below was written for a mod_perl module. When I make many connections to the server that causes this module to be run (subsequently executing the subroutine below) Apache's error_log contains many lines "ERROR Interrupted system call". By adding some debugging statements, I have discovered that this happens a few thousand times before stopping and uses up most/all of the cpu on the machine. What could be the cause of this? From the manpage I see EINTR is caused by an un-handled signal. Is there a way to tell what signal is causing this or where it came from?

Thanks for any help!

rr

#!/usr/bin/perl -w use strict; use Symbol; use Fcntl qw(:DEFAULT); use Socket; use Time::HiRes; print STDOUT simple("localhost", 80, "GET / HTTP/1.1\012Host:bidtxt.wh +enu.com\012\012"); exit 0; sub simple { my $host = shift || return undef; my $port = shift || return undef; my $mesg = shift || return undef; my $timeout = shift || 60; my $t0 = Time::HiRes::time(); my $ti; my $proto = getprotobyname('tcp'); my $iaddr = inet_aton($host) || return undef; my $paddr = sockaddr_in($port, $iaddr); my $s = Symbol::gensym; socket($s, PF_INET, SOCK_STREAM, $proto) || return undef; connect($s, $paddr) || return undef; my $fd = fileno($s); my $t; my $b; my $res; my $nf; my $tl; my $buf = "\000" x 8120; ## BUFSIZ my $l = length($mesg); my $rin = 0 ; my $win = 0 , my $ein = 0; my $rout = 0; my $wout = +0; my $eout = 0; vec($rin, $fd, 1) = 1; vec($win, $fd, 1) = 1; $ein = $rin | $win; my $i; $t = 0; $b = 0; while (($nf, $tl) = select(undef, $wout=$win, $eout=$ein, 2)) { $i++; $ti = Time::HiRes::time() - $t0; if ($ti > $timeout) { print STDERR "Timed out writing ($ti) $!\n"; shutdown($s, 2); return undef; } if (vec($wout, $fd, 1) == 1) { $b = syswrite($s, $mesg, $l - $b, $b); $t = $t + $b; last if $t = $l; } if (vec($eout, $fd, 1) == 1) { print STDERR "Got an error while writing: $!\n"; shutdown($s, 2); return undef; } } $t = 0; $l = 0; $b = 0; while (($nf, $tl) = select($rout=$rin, undef, $eout=$ein, 2)) { $i++; $ti = Time::HiRes::time() - $t0; if ($!) { print STDERR "ERROR $!\n"; } if ($ti > $timeout) { print STDERR "Timed out reading ($ti) $!\n"; shutdown($s, 2); return undef; } if (vec($rout, $fd, 1) == 1) { $b = sysread($s, $buf, 8192); $t = $t + $b; last if $b == 0; $res .= $buf; } if (vec($eout, $fd, 1) == 1) { print STDERR "Got an error while reading: $!\n"; shutdown($s, 2); return undef; } } shutdown($s, 2); return $res; }

In reply to 2 problems using sockets perl 5.8 and mod_perl2 on Linux by rr

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.