Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make the PRINT method return the number of bytes written.

This complies with the IO:: interface, and fixes (and takes the patch from)
RT#24347
  • Loading branch information...
commit 29829dde9ff0a0124a835bff4bdf747fede6dc48 1 parent c9234f8
Tomas Doran authored
3  perl/ChangeLog
... ...
@@ -1,3 +1,6 @@
  1
+    o Make the PRINT method return the number of bytes written rather than
  2
+      undef to be consistent with the IO:: interface. Fixes RT#24347
  3
+      <David Dick>
1 4
     o Fix UTF-8 double encoding when FCGI is passed octets by downgrading
2 5
       them into bytes correctly. Fixes RT#52400 <chansen@cpan.org>
3 6
 
6  perl/FCGI.PL
@@ -261,9 +261,13 @@ sub READ {
261 261
 
262 262
 sub PRINT {
263 263
     my ($stream) = shift;
  264
+    my $bytes = 0;
264 265
     for (@_) {
265  
-	$stream->{src}->write($stream->{type}, $_, length($_));
  266
+        my $len = length($_);
  267
+        $stream->{src}->write($stream->{type}, $_, $len);
  268
+        $bytes += $len;
266 269
     }
  270
+    return $bytes;
267 271
 }
268 272
 
269 273
 sub CLOSE {
19  perl/FCGI.XL
@@ -533,15 +533,19 @@ MODULE = FCGI		PACKAGE = FCGI::Stream
533 533
 
534 534
 #ifndef USE_SFIO
535 535
 
536  
-void
  536
+int
537 537
 PRINT(stream, ...)
538 538
 	FCGI::Stream	stream;
539 539
 
540 540
 	PREINIT:
541 541
 	int	n;
  542
+    int retval;
  543
+    int bytes_written;
542 544
 
543 545
 	CODE:
544  
-	for (n = 1; n < items; ++n) {
  546
+    retval = 0;
  547
+    bytes_written = 0;
  548
+    for (n = 1; n < items && bytes_written >= 0; ++n) {
545 549
             STRLEN len;
546 550
             register char *tmps; 
547 551
 #ifdef DO_UTF8
@@ -549,10 +553,17 @@ PRINT(stream, ...)
549 553
                 croak("Wide character in FCGI::Stream::PRINT");
550 554
 #endif
551 555
             tmps = (char *)SvPV(ST(n),len);
552  
-            FCGX_PutStr(tmps, len, stream);
553  
-	}
  556
+	        bytes_written = FCGX_PutStr(tmps, len, stream);
  557
+            if (bytes_written > 0) {
  558
+                retval += bytes_written;
  559
+            }
  560
+    }
554 561
 	if (SvTRUEx(perl_get_sv("|", FALSE))) 
555 562
 	    FCGX_FFlush(stream);
  563
+    RETVAL = retval;
  564
+
  565
+    OUTPUT:
  566
+    RETVAL
556 567
 
557 568
 int
558 569
 WRITE(stream, bufsv, len, ...)

0 notes on commit 29829dd

Please sign in to comment.
Something went wrong with that request. Please try again.