Index: [Article Count Order] [Thread]

Date:  Sat, 11 Sep 2004 01:26:45 +0900
From:  Shugo Maeda <shugo@...>
Subject:  Re: send_fd broken under Apache2 ?
To:  modruby@... (modruby ML)
Message-Id:  <4141D5C5.4000704@...>
In-Reply-To:  <41416A5B.3090906@...>
References:  <opsdlk9hfhap9h0v@...> <200408312204.FMLAAB24180.modruby@...> <opsdovzra5ap9h0v@...> <41416A5B.3090906@...>
X-Mail-Count: 01293



Hi,

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

Sorry, please forget it and use this patch instead.

Shugo



Index: request.c
===================================================================
--- request.c	(revision 30)
+++ request.c	(working copy)
@@ -1472,12 +1472,15 @@
 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;
+    struct stat st;
 #else
     long bytes_sent;
 #endif
-    request_data *data;
 
     request_set_sync(self, Qtrue);
     rb_apache_request_flush(self);    
@@ -1486,7 +1489,14 @@
     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");
+    }
+    if (fstat(fileno(fptr->f), &st) == -1) {
+	rb_sys_fail(fptr->path);
+    }
+    ap_send_fd(file, data->request, 0, st.st_size, &bytes_sent);
 #else
     bytes_sent = ap_send_fd_length(fptr->f, data->request, -1);
 #endif