Index: [Article Count Order] [Thread]

Date:  Fri, 10 Sep 2004 17:48:27 +0900
From:  Shugo Maeda <shugo@...>
Subject:  Re: send_fd broken under Apache2 ?
To:  modruby@... (modruby ML)
Message-Id:  <41416A5B.3090906@...>
In-Reply-To:  <opsdovzra5ap9h0v@...>
References:  <opsdlk9hfhap9h0v@...> <200408312204.FMLAAB24180.modruby@...> <opsdovzra5ap9h0v@...>
X-Mail-Count: 01292



Hi,
Sorry to be late.

Katarina WONG wrote:
> I am trying to use send_fd under Apache 2.0.50 (with mod_ruby svn 
> revision  30) but no luck. This code
> works fine with Apache 1.3.31 but when launched under 2.0.50, the
> answering httpd starts eating up all the CPU with no response.
(snip)
> File.open( fileName ) { |file| r.send_fd(file) }

Apache::Request#send_fd was broken on Apache2:(
Can you try the attaced patch?

Shugo





Index: request.c
===================================================================
--- request.c	(revision 30)
+++ request.c	(working copy)
@@ -1472,12 +1472,14 @@
 static VALUE request_send_fd(VALUE self, VALUE io)
 {
     OpenFile *fptr;
+    request_data *data;
 #ifdef APACHE2
     apr_size_t bytes_sent;
+    apr_file_t *file;
+    int fd;
 #else
     long bytes_sent;
 #endif
-    request_data *data;
 
     request_set_sync(self, Qtrue);
     rb_apache_request_flush(self);    
@@ -1486,7 +1488,11 @@
     GetOpenFile(io, fptr);
 
 #ifdef APACHE2
-    ap_send_fd((apr_file_t *)fptr->f, data->request, 0, -1, &bytes_sent);
+    fd = fileno(fptr->f);
+    if (apr_os_file_put(&file, &fd, 0, data->request->pool) != APR_SUCCESS) {
+	rb_raise(rb_eIOError, "apr_os_file_put() failed");
+    }
+    ap_send_fd(file, data->request, 0, -1, &bytes_sent);
 #else
     bytes_sent = ap_send_fd_length(fptr->f, data->request, -1);
 #endif