You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nikolay Ananiev <an...@thegdb.com> on 2005/09/15 23:25:24 UTC

Is it possible to create a file bucket?

I'd like to do the following:
open $fh, '<', 'some_file'; # A very big file
$b =  APR::Bucket->new($ba, $fh);

while($b->read($buffer, 2048)) {
...
}

or
$b =  APR::Bucket->new($ba, \*STDIN);







Re: Is it possible to create a file bucket?

Posted by Nikolay Ananiev <an...@thegdb.com>.
I'd like to use APR::Request's custom parser under some different
environments
like FastCGI, PerlEx and PersistentPerl. All these tie STDIN to some
package, which defines
methods to read a particular socket.  APR::Request::CGI doesn't work,
because the
operating system's STDIN is not used.

Currently, to feed APR::Request's parser I have to do the following:
$length = $ENV{CONTENT_LENGTH};
read(STDIN, $buffer, $length);
[...]
$b =  APR::Bucket->new($ba, $buffer);
[...]

This works nice for simple requests, but not good for file uploads,
especially not good for the previously mentioned environments,
because they are persistent just like mod_perl and filling $buffer to the
limit would take a lot of RAM, which is bad.

If I understand the "file bucket" conception right, if I supply a file
handle
instead of a scalar to APR::Bucket->new, it should work as desired,
because APR::Request's parser has a way to limit the number of bytes read.

APR's documentation says something about file buckets:

"It's important to know that certain bucket types (e.g. file bucket),
may perform a split and insert extra buckets following the current
one. Therefore never call C<L<$b-E<gt>remove|/C_remove_>>, before
calling C<$b-E<gt>read>, or you may lose data."

but it doesn't say how to create one.

Apache2::TieBucketBrigade won't work for me.

"Will Whittaker" <mo...@hairljkscpq.mailchannels.com> wrote in message
news:20050915214523.GH19195@mailchannels.com...
>
> On Fri, Sep 16, 2005 at 12:25:24AM +0300, Nikolay Ananiev wrote:
> >
> >
> > I'd like to do the following:
> > open $fh, '<', 'some_file'; # A very big file
> > $b =  APR::Bucket->new($ba, $fh);
> >
> > while($b->read($buffer, 2048)) {
> > .....
> > }
> >
> > or
> > $b =  APR::Bucket->new($ba, \*STDIN);
> >
> >
> >
> >
> >
> >
> I'm not sure what you are trying to do in the above.  If you are trying to
> make brigades usuable as filehandles then try Apache2::TieBucketBrigade
> http://search.cpan.org/~mock/Apache2-TieBucketBrigade-0.07/
>
> mock
>




Re: Is it possible to create a file bucket?

Posted by Will Whittaker <mo...@hairljkscpq.mailchannels.com>.
On Fri, Sep 16, 2005 at 12:25:24AM +0300, Nikolay Ananiev wrote:
> 
> 
> I'd like to do the following:
> open $fh, '<', 'some_file'; # A very big file
> $b =  APR::Bucket->new($ba, $fh);
> 
> while($b->read($buffer, 2048)) {
> .....
> }
> 
> or
> $b =  APR::Bucket->new($ba, \*STDIN);
> 
> 
> 
> 
> 
> 
I'm not sure what you are trying to do in the above.  If you are trying to
make brigades usuable as filehandles then try Apache2::TieBucketBrigade
http://search.cpan.org/~mock/Apache2-TieBucketBrigade-0.07/

mock

Re: Is it possible to create a file bucket?

Posted by Frank Wiles <fr...@wiles.org>.
On Fri, 16 Sep 2005 00:25:24 +0300
"Nikolay Ananiev" <an...@thegdb.com> wrote:

> I'd like to do the following:
> open $fh, '<', 'some_file'; # A very big file
> $b =  APR::Bucket->new($ba, $fh);
> 
> while($b->read($buffer, 2048)) {
> ...
> }
> 
> or
> $b =  APR::Bucket->new($ba, \*STDIN);

  Why would you want to do that?  Just use normal file usage or
  if you really want to read it by exactly 2048 bytes at a time
  something like sysread().  

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------