dougm 01/04/28 12:29:45
Modified: lib/Apache compat.pm
xs/maps apache_functions.map
Added: t/api send_fd.t
t/response/TestAPI send_fd.pm
Log:
add send_fd compat method and tests
Revision Changes Path
1.3 +34 -0 modperl-2.0/lib/Apache/compat.pm
Index: compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- compat.pm 2001/04/20 03:07:53 1.2
+++ compat.pm 2001/04/28 19:29:39 1.3
@@ -112,5 +112,39 @@
return \$data;
}
+use constant IOBUFSIZE => 8192;
+
+#XXX: howto convert PerlIO to apr_file_t
+#so we can use the real ap_send_fd function
+#2.0 ap_send_fd() also has an additional offset parameter
+
+sub send_fd_length {
+ my($r, $fh, $length) = @_;
+
+ my $buff;
+ my $total_bytes_sent = 0;
+ my $len;
+
+ return 0 if $length == 0;
+
+ if (($length > 0) && ($total_bytes_send + IOBUFSIZE) > $length) {
+ $len = $length - $total_bytes_sent;
+ }
+ else {
+ $len = IOBUFSIZE;
+ }
+
+ while (read($fh, $buff, $len)) {
+ $total_bytes_sent += $r->puts($buff);
+ }
+
+ $total_bytes_sent;
+}
+
+sub send_fd {
+ my($r, $fh) = @_;
+ $r->send_fd_length($fh, -1);
+}
+
1;
__END__
1.1 modperl-2.0/t/api/send_fd.t
Index: send_fd.t
===================================================================
use strict;
use warnings FATAL => 'all';
use Test;
use Apache::TestConfig ();
plan tests => 3;
my $config = Apache::TestConfig->thaw;
my $url = '/TestAPI::send_fd';
my $data = $config->http_raw_get($url);
ok $data;
my $module = 'response/TestAPI/send_fd.pm';
ok length($data) == -s $module;
$data = $config->http_raw_get("$url?noexist.txt");
ok $data =~ /Not Found/;
1.1 modperl-2.0/t/response/TestAPI/send_fd.pm
Index: send_fd.pm
===================================================================
package TestAPI::send_fd;
use strict;
use warnings FATAL => 'all';
use Apache::compat ();
sub handler {
my $r = shift;
my $file = $r->args || __FILE__;
open my $fh, $file or return Apache::NOT_FOUND;
my $bytes = $r->send_fd($fh);
return Apache::SERVER_ERROR unless $bytes == -s $file;
Apache::OK;
}
1;
1.14 +1 -1 modperl-2.0/xs/maps/apache_functions.map
Index: apache_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/apache_functions.map,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- apache_functions.map 2001/04/24 02:26:19 1.13
+++ apache_functions.map 2001/04/28 19:29:44 1.14
@@ -94,7 +94,7 @@
ap_rationalize_mtime
ap_update_mtime
ap_send_error_response
- ap_send_fd
+~ap_send_fd
ap_send_mmap
ap_send_size
ap_set_keepalive