You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Manoj Bist <ma...@gmail.com> on 2007/08/17 06:21:16 UTC

modperl and fprintf(stdout,...)

Hi,

I would really appreciate if someone could answer the following question
regarding modperl and writing to stdout for me:

I have a perl binding for a C library which generates binary(audio/video)
data.  To push this binary data over an HTTP response, fprintf(stdout,...)
does not work in context of modperl.
Do I have to copy the binary data to a perl scalar variable and then do
$r->print(...) in the perl script?

Please do let me know if I need to provide more details.

Thanks,

Manoj.

Re: modperl and fprintf(stdout,...)

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Manoj Bist wrote:
> Hi,
> 
> I would really appreciate if someone could answer the following question
> regarding modperl and writing to stdout for me:
> 
> I have a perl binding for a C library which generates binary(audio/video)
> data.  To push this binary data over an HTTP response, fprintf(stdout,...)
> does not work in context of modperl.
> Do I have to copy the binary data to a perl scalar variable and then do
> $r->print(...) in the perl script?

if your binding is in XS you can just use the apache API directly from
your XS module.  something like ap_send_fd() should do the trick if you
have an open fd.  otherwise you'll need to write out buckets in httpd
2.x or use another raw means of streaming the response across the wire.

but to the root of your question, no, you shouldn't need to copy the
data once you have it, provided you work from within XS - use use the
httpd api, for which there are many examples in the httpd distribution
(choose one of the generator modules, like cgi or something).

HTH

--Geoff

Re: modperl and fprintf(stdout,...)

Posted by Perrin Harkins <pe...@elem.com>.
On 8/17/07, Manoj Bist <ma...@gmail.com> wrote:
> I have a perl binding for a C library which generates binary(audio/video)
> data.  To push this binary data over an HTTP response, fprintf(stdout,...)
> does not work in context of modperl.
> Do I have to copy the binary data to a perl scalar variable and then do
> $r->print(...) in the perl script?

This is a little outside of my Apache internals knowledge, but the way
this used to work is that mod_perl would make STDOUT run through
$r->print when you print something from Perl.  (The mechanism for this
changed over the years and I've lost track of how it works in mod_perl
2.)  Your C library will not get that, and will probably need to print
things the same way that an Apache module in C would.  I imagine you
could pass it the needed Apache structures from perl, or you could do
as you mentioned and have it send the data back in a form that you can
read in perl.

- Perrin