On Thu 04 Sep 2008, Tina Müller wrote:
> $pid = open3($wtr, $rdr, $err,
> '/usr/bin/source-highlight', '-s', 'perl', '-css',
> '--no-doc');
> print $wtr $content;
> close $wtr;
> warn __PACKAGE__.':'.__LINE__.": before read loop\n";
> while (<$rdr>) {
> # this is not executed
> warn __PACKAGE__.':'.__LINE__.": line $_\n";
> $highlighted .= $_;
> }
Don't know if it relates to the problem but this code is quite fragile.
It depends upon whether $content completely fits into the operating
systems pipe buffer. In your program the print $wtr or the close $wtr
statements may infinitely block if $content is too large.
To illustrate that try this:
perl -e 'pipe my ($r, $w) or die "pipe: $!\n"; print $w "x"x64000;
warn "printed\n"; close $w;'
Here a pipe is created and written to but never read from. This example
succeeds on my linux box. If 64000 is raised to 69000 the "print $w"
succeeds and I see the output of warn(). But the process never ends. It
is blocked in the close() operation. If the buffer length is raised a
bit further to 70000 I don't even see the warning. The process is
blocked in the print() operation. The pipe buffer size depends upon the
operating system. So your numbers may vary.
I'd recommend to rewrite that piece based on either perl's select(),
IO::Select or some kind of event library like Lib::Event, EV, Event or
even POE. In all cases you have to use non-blocking IO for reading and
writing combined with sysread/syswrite.
Further, I'd suggest a bit of error handling. All those operations
open3, print, close may fail. Only open3 reports the failure via an
exception.
Also, you may want to watch out for SIGPIPE.
Torsten
--
Need professional mod_perl support?
Just hire me: [EMAIL PROTECTED]