take 2 on that patch, this one adds a check so ap_setup_client_block() is
only called once.  with this part of the fix you can call $r->content
multiple times without hanging:

my $data = $r->content;
$data = $r->content;

however, any calls to $r->content after the first will return undef.
(unless you happen to subclass and override the content method to cache
the read data somewhere)

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.109
diff -u -r1.109 Apache.xs
--- src/modules/perl/Apache.xs  2000/09/27 16:25:56     1.109
+++ src/modules/perl/Apache.xs  2000/09/27 19:38:34
@@ -954,22 +954,27 @@
     int      bufsiz
 
     PREINIT:
-    long nrd = 0;
+    long nrd = 0, old_read_length;
     int rc;
 
     PPCODE:
-    if ((rc = setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
-       aplog_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, r->server, 
-                   "mod_perl: setup_client_block failed: %d", rc);
-       XSRETURN_UNDEF;
+    if (!r->read_length) {
+        if ((rc = setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
+            aplog_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, r->server, 
+                        "mod_perl: setup_client_block failed: %d", rc);
+            XSRETURN_UNDEF;
+        }
     }
 
+    old_read_length = r->read_length;
+    r->read_length = 0;
+
     if (should_client_block(r)) {
         SvUPGRADE(buffer, SVt_PV);
         SvGROW(buffer, bufsiz+1);
         nrd = get_client_block(r, SvPVX(buffer), bufsiz);
-        r->read_length = 0;
-    } 
+    }
+    r->read_length += old_read_length;
 
     if (nrd > 0) {
         XPUSHs(sv_2mortal(newSViv((long)nrd)));

Reply via email to