Permalink
Browse files

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...
bobtfish committed Jan 10, 2010
1 parent c9234f8 commit 29829dde9ff0a0124a835bff4bdf747fede6dc48
Showing with 23 additions and 5 deletions.
  1. +3 −0 perl/ChangeLog
  2. +5 −1 perl/FCGI.PL
  3. +15 −4 perl/FCGI.XL
View
@@ -1,3 +1,6 @@
+ o Make the PRINT method return the number of bytes written rather than
+ undef to be consistent with the IO:: interface. Fixes RT#24347
+ <David Dick>
o Fix UTF-8 double encoding when FCGI is passed octets by downgrading
them into bytes correctly. Fixes RT#52400 <chansen@cpan.org>
View
@@ -261,9 +261,13 @@ sub READ {
sub PRINT {
my ($stream) = shift;
+ my $bytes = 0;
for (@_) {
- $stream->{src}->write($stream->{type}, $_, length($_));
+ my $len = length($_);
+ $stream->{src}->write($stream->{type}, $_, $len);
+ $bytes += $len;
}
+ return $bytes;
}
sub CLOSE {
View
@@ -533,26 +533,37 @@ MODULE = FCGI PACKAGE = FCGI::Stream
#ifndef USE_SFIO
-void
+int
PRINT(stream, ...)
FCGI::Stream stream;
PREINIT:
int n;
+ int retval;
+ int bytes_written;
CODE:
- for (n = 1; n < items; ++n) {
+ retval = 0;
+ bytes_written = 0;
+ for (n = 1; n < items && bytes_written >= 0; ++n) {
STRLEN len;
register char *tmps;
#ifdef DO_UTF8
if (DO_UTF8(ST(n)) && !sv_utf8_downgrade(ST(n), 1))
croak("Wide character in FCGI::Stream::PRINT");
#endif
tmps = (char *)SvPV(ST(n),len);
- FCGX_PutStr(tmps, len, stream);
- }
+ bytes_written = FCGX_PutStr(tmps, len, stream);
+ if (bytes_written > 0) {
+ retval += bytes_written;
+ }
+ }
if (SvTRUEx(perl_get_sv("|", FALSE)))
FCGX_FFlush(stream);
+ RETVAL = retval;
+
+ OUTPUT:
+ RETVAL
int
WRITE(stream, bufsv, len, ...)

0 comments on commit 29829dd

Please sign in to comment.