You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Todd Caine <to...@eli.net> on 2000/08/02 22:30:09 UTC
Client filehandle?
I've got a Perl Module which has a function called
RRDs::graph($args), that will only print to stdout. In my
handler I write something similar to:
sub handler {
my $r = shift;
# I want the output to go to the client, ($r->print()),
but instead it will only go to STDOUT
RRDs::graph($args);
return OK;
}
So I was trying something like:
*STDOUT = \*r{IO};
hoping that:
RRDs::graph would print to the socket instead of stdout.
Is there anyway to access the clients file descriptor?
Thanks in advance....
Todd
--
--------------------------------------------------------------
<!-- Todd Caine - tcaine@eli.net
Electric Lightwave, Inc.
4400 NE 77th Avenue
Vancouver, WA 98662
Direct Dial: (360) 816-4344 //-->
--------------------------------------------------------------
Re: Client filehandle?
Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 2 Aug 2000, Todd Caine wrote:
> > STDOUT is where $r->print goes under mod_perl; you should be OK.
>
> The data that is printed out via $r->print is on the file descriptor that the
> http request is set up on. If the HTTP request came in on file descriptor 3
> then $r->print('foo') prints to file descriptor 3; not stdout(file descriptor
> 1, on my system).
right, Perl STDOUT != C stdout
> The only way I can get part of gif to the browser was to do this:
>
> my $c = $r->connection;
> my $fd_num = $c->fileno(0);
> open(STDOUT, ">&$fd_num");
> RRDs::graph($args);
>
> But the data is incomplete. Even when I autoflush the $fd_num.
> There has got to be a better way.....
see Apache::Magick in the eagle book or at modperl.com. it's still ugly
since it writes to a tmpfile, but it works. you can also modify your c
sources to redfine stdout-ish calls, Apache::Peek does something like that
for redirecting stderr to the client socket:
#define PerlIO request_rec
#define PerlIO_printf rprintf
#define PerlIO_vprintf(r,fmt,vlist) \
vbprintf(r->connection->client, fmt, vlist)
#define PerlIO_stderr() perl_request_rec(NULL)
#define PerlIO_putc(r,c) rputc(c,r)
#define PerlIO_puts(r,s) rputs(s,r)
Re: Client filehandle?
Posted by Todd Caine <to...@eli.net>.
darren chamberlain wrote:
> Todd Caine (todd_caine@eli.net) said something to this effect:
> > I've got a Perl Module which has a function called
> > RRDs::graph($args), that will only print to stdout. In my
> > handler I write something similar to:
>
> STDOUT is where $r->print goes under mod_perl; you should be OK.
The data that is printed out via $r->print is on the file descriptor that the
http request is set up on. If the HTTP request came in on file descriptor 3
then $r->print('foo') prints to file descriptor 3; not stdout(file descriptor
1, on my system).
>
>
> Failing this, does RRDs::graph print explicitly to STDOUT, or just to
> the currently selected filehandle? If the latter (it probably is),
> just select a a different filehandle, and then call &graph.
>
RRDs::graph is perl wrapper for the RRDTool utility written in C. It
explicitly prints to 'stdout'. I've tried selecting on a different file
descriptor like this:
my $c = $r->connection;
my $fd_num = $c->fileno(0);
select($fd_num);
And I get "The document contained no data".
The only way I can get part of gif to the browser was to do this:
my $c = $r->connection;
my $fd_num = $c->fileno(0);
open(STDOUT, ">&$fd_num");
RRDs::graph($args);
But the data is incomplete. Even when I autoflush the $fd_num.
There has got to be a better way.....
Thanks for your thoughts,
Todd
>
> (darren)
>
> --
> Without deviation from the norm, 'progress' is not possible. -- Frank Zappa
--
--------------------------------------------------------------
<!-- Todd Caine - tcaine@eli.net
Electric Lightwave, Inc.
4400 NE 77th Avenue
Vancouver, WA 98662
Direct Dial: (360) 816-4344 //-->
--------------------------------------------------------------
Re: Client filehandle?
Posted by darren chamberlain <da...@boston.com>.
Todd Caine (todd_caine@eli.net) said something to this effect:
> I've got a Perl Module which has a function called
> RRDs::graph($args), that will only print to stdout. In my
> handler I write something similar to:
STDOUT is where $r->print goes under mod_perl; you should be OK.
Failing this, does RRDs::graph print explicitly to STDOUT, or just to
the currently selected filehandle? If the latter (it probably is),
just select a a different filehandle, and then call &graph.
(darren)
--
Without deviation from the norm, 'progress' is not possible. -- Frank Zappa
RE: Client filehandle?
Posted by Douglas Wilson <do...@racesearch.com>.
> -----Original Message-----
> From: Douglas Wilson [mailto:dougw@racesearch.com]
> Sent: Wednesday, August 02, 2000 3:24 PM
> To: Todd Caine; mod_perl
> Subject: RE: Client filehandle?
> Maybe (and I mean MAYBE):
> local *STDOUT = \*$r;
And of course, that should have been
(hey I'm making it up & learning as I go along):
local *STDOUT = $r;
HTH,
Douglas Wilson
RE: Client filehandle?
Posted by Douglas Wilson <do...@racesearch.com>.
> -----Original Message-----
> From: Todd Caine [mailto:todd_caine@eli.net]
> Sent: Wednesday, August 02, 2000 1:30 PM
> To: mod_perl
> Subject: Client filehandle?
>
>
> I've got a Perl Module which has a function called
> RRDs::graph($args), that will only print to stdout. In my
> handler I write something similar to:
>
> sub handler {
> my $r = shift;
>
> # I want the output to go to the client, ($r->print()),
> but instead it will only go to STDOUT
> So I was trying something like:
>
> *STDOUT = \*r{IO};
Maybe (and I mean MAYBE):
local *STDOUT = \*$r;
HTH,
Douglas Wilson