perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug MacEachern <do...@covalent.net>
Subject Re: syswrite/WRITE patch - Take one
Date Wed, 20 Dec 2000 07:51:35 GMT
On Fri, 13 Oct 2000, Soheil Seyfaie wrote:

> 
> The following patch *should* work. Suggestions welcome.

many thanks soheil, great that you included the tests too.
i have applied your patch, but a slightly different version (see below).
i left this out:

> + 
> +     if(!mod_perl_sent_header(r, 0)) {
> + 	croak("HTTP headers missing. Please send HTTP headers first!");
> + 	XSRETURN_IV(0);
> +     }

doesn't seem right for the write method to croak like this.  why did you
want todo that?

and the new version also includes tighter parameter checking.

Index: src/modules/perl/Apache.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.116
diff -u -r1.116 Apache.xs
--- src/modules/perl/Apache.xs	2000/12/20 07:02:49	1.116
+++ src/modules/perl/Apache.xs	2000/12/20 07:51:36
@@ -1035,6 +1035,54 @@
     }
 
 int
+write(r, sv_buffer, sv_length=-1, offset=0)
+    Apache	r
+    SV *sv_buffer
+    int sv_length
+    int offset
+
+    ALIAS:
+    Apache::WRITE = 1
+
+    PREINIT:
+    STRLEN len;
+    char *buffer;
+    int sent = 0;
+
+    CODE:
+    ix = ix; /* avoid -Wall warning */
+    RETVAL = 0;
+
+    if (r->connection->aborted) {
+        XSRETURN_UNDEF;
+    }
+
+    buffer = SvPV(sv_buffer, len);
+    if (sv_length != -1) {
+        len = sv_length;
+    }
+
+    if (offset) {
+        buffer += offset;
+    }
+
+    while (len > 0) {
+        sent = rwrite(buffer,
+                      len < HUGE_STRING_LEN ? len : HUGE_STRING_LEN,
+                      r);
+        if (sent < 0) {
+            rwrite_neg_trace(r);
+	    break;
+        }
+        buffer += sent;
+        len -= sent;
+        RETVAL += sent;
+    }
+
+    OUTPUT:
+    RETVAL
+
+int
 print(r, ...)
     Apache	r
 


Mime
View raw message