=head1 NAME
Apache2::RequestIO - Perl API for Apache request record IO
=head1 Synopsis
use Apache2::RequestIO ();
$rc = $r->discard_request_body();
$r->print("foo", "bar");
$r->puts("foo", "bar"); # same as print, but no flushing
$r->printf("%s $d", "foo", 5);
$r->read($buffer, $len);
$r->rflush();
$r->sendfile($filename);
$r->write("foobartarcar", 3, 5);
=head1 Description
C provides the API to perform IO on the L.
=head1 API
C provides the following functions and/or methods:
=head2 C
In HTTP/1.1, any method can have a body. However, most GET handlers
wouldn't know what to do with a request body if they received one.
This helper routine tests for and reads any message body in the
request, simply discarding whatever it receives. We need to do this
because failing to read the request body would cause it to be
interpreted as the next request on a persistent connection.
$rc = $r->discard_request_body();
=over 4
=item obj: C
( C> )
The current request
=item ret: C ( integer )
C> if request
is malformed, C otherwise.
=item since: 2.0.00
=back
Since we return an error status if the request is malformed, this
routine should be called at the beginning of a no-body handler, e.g.,
use Apache2::Const -compile => qw(OK);
$rc = $r->discard_request_body;
return $rc if $rc != Apache2::Const::OK;
=head2 C
Send data to the client.
$cnt = $r->print(@msg);
=over 4
=item obj: C
( C> )
=item arg1: C ( ARRAY )
Data to send
=item ret: C ( number )
How many bytes were sent (or buffered). If zero bytes were
sent, C will return C<0E0>, or "zero but true," which
will still evaluate to C<0> in a numerical context.
=item excpt: C>
=item since: 2.0.00
=back
The data is flushed only if STDOUT stream's C is true. Otherwise
it's buffered up to the size of the buffer, flushing only excessive
data.
=head2 C
Format and send data to the client (same as C).
$cnt = $r->printf($format, @args);
=over 4
=item obj: C
( C> )
=item arg1: C ( string )
Format string, as in the Perl core C function.
=item arg2: C ( ARRAY )
Arguments to be formatted, as in the Perl core C function.
=item ret: C ( number )
How many bytes were sent (or buffered)
=item excpt: C>
=item since: 2.0.00
=back
The data is flushed only if STDOUT stream's C is true. Otherwise
it's buffered up to the size of the buffer, flushing only excessive
data.
=head2 C
Send data to the client
$cnt = $r->puts(@msg);
=over 4
=item obj: C
( C> )
=item arg1: C ( ARRAY )
Data to send
=item ret: C ( number )
How many bytes were sent (or buffered)
=item excpt: C>
=item since: 2.0.00
=back
C is similar to C>, but it won't attempt
to flush data, no matter what the value of STDOUT stream's C
is. Therefore assuming that STDOUT stream's C is true, this method
should be a tiny bit faster than C>, especially
if small strings are printed.
=head2 C
Read data from the client.
$cnt = $r->read($buffer, $len);
$cnt = $r->read($buffer, $len, $offset);
=over 4
=item obj: C
( C> )
=item arg1: C ( SCALAR )
The buffer to populate with the read data
=item arg2: C ( number )
How many bytes to attempt to read
=item opt arg3: C ( number )
If a non-zero C is specified, the read data will be placed at
that offset in the C.
META: negative offset and \0 padding are not supported at the moment
=item ret: C ( number )
How many characters were actually read
=item excpt: C>
=item since: 2.0.00
=back
This method shares a lot of similarities with the Perl core C
function. The main difference in the error handling, which is done via
C>
=head2 C
Flush any buffered data to the client.
$r->rflush();
=over 4
=item obj: C
( C> )
=item ret: no return value
=item since: 2.0.00
=back
Unless STDOUT stream's C is false, data sent via
Cprint()|/C_print_>> is buffered. This method flushes that
data to the client.
=head2 C
Send a file or a part of it
$rc = $r->sendfile($filename);
$rc = $r->sendfile($filename, $offset);
$rc = $r->sendfile($filename, $offset, $len);
=over 4
=item obj: C
( C> )
=item arg1: C ( string )
The full path to the file (using C> on all systems)
=item opt arg2: C ( integer )
Offset into the file to start sending.
No offset is used if C is not specified.
=item opt arg3: C ( integer )
How many bytes to send.
If not specified the whole file is sent (or a part of it, if
C if specified)
=item ret: C ( C> )
On success,
C> is
returned.
In case of a failure -- a failure code is returned, in which case
normally it should be returned to the caller.
=item excpt: C>
Exceptions are thrown only when this function is called in the VOID
context. So if you don't want to handle the errors, just don't ask for
a return value and the function will handle all the errors on its own.
=item since: 2.0.00
=back
=head2 C
Send partial string to the client
$cnt = $r->write($buffer);
$cnt = $r->write($buffer, $len);
$cnt = $r->write($buffer, $len, $offset);
=over 4
=item obj: C
( C> )
=item arg1: C ( SCALAR )
The string with data
=item opt arg2: C ( SCALAR )
How many bytes to send. If not specified, or -1 is specified, all the
data in C (or starting from C) will be sent.
=item opt arg3: C ( number )
Offset into the C string.
=item ret: C ( number )
How many bytes were sent (or buffered)
=item excpt: C>
=item since: 2.0.00
=back
Examples:
Assuming that we have a string:
$string = "123456789";
Then:
$r->write($string);
sends:
123456789
Whereas:
$r->write($string, 3);
sends:
123
And:
$r->write($string, 3, 5);
sends:
678
Finally:
$r->write($string, -1, 5);
sends:
6789
=head1 TIE Interface
The TIE interface implementation. This interface is used for HTTP
request handlers, when running under C> and
Perl doesn't have perlio enabled.
See the I manpage for more information.
=head2 C
=over 4
=item since: 2.0.00
=back
NoOP
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
NoOP
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
NoOP
See the I Perl entry in the I manpage
=head2 C
=over 4
=item since: 2.0.00
=back
See the I Perl entry in the I manpage
=head1 Deprecated API
The following methods are deprecated, Apache plans to remove those in
the future, therefore avoid using them.
=head2 C
This method is deprecated since the C implementation is buggy and we
don't want you to use it at all. Instead use the plain
Cread()|/C_read_>>.
=head2 C
This method is deprecated since
Cget_client_block|/C__get_client_block_>> is deprecated.
=head2 C
This method is deprecated since
Cget_client_block|/C__get_client_block_>> is deprecated.
=head1 See Also
L.
=head1 Copyright
mod_perl 2.0 and its core modules are copyrighted under
The Apache Software License, Version 2.0.
=head1 Authors
L.
=cut