summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2006-04-20 17:43:18 +0000
committerMichael Wallner <mike@php.net>2006-04-20 17:43:18 +0000
commitf7a6327728387e0420c12a33f710053132c6fb26 (patch)
tree6fd1d8b994c6758a8892dd123d1bcdc61ccf1d1c
parentbdef85af21146b462ebf8e13cf3a34162f02d7bd (diff)
downloadphp-git-f7a6327728387e0420c12a33f710053132c6fb26.tar.gz
- Fix reading stream filters never notified about EOF
-rw-r--r--NEWS1
-rw-r--r--ext/standard/tests/filters/read.phpt72
-rwxr-xr-xmain/streams/streams.c4
3 files changed, 75 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 4775397628..ff0610fc4a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? Apr 2006, PHP 5.1.3
+- Fixed reading stream filters never notified about EOF. (Mike)
- Fixed bug #37138 (__autoload tries to load callback'ed self and parent).
(Dmitry)
- Fixed bug #37103 (libmbfl headers not installed). (Jani)
diff --git a/ext/standard/tests/filters/read.phpt b/ext/standard/tests/filters/read.phpt
new file mode 100644
index 0000000000..a2372cf8f9
--- /dev/null
+++ b/ext/standard/tests/filters/read.phpt
@@ -0,0 +1,72 @@
+--TEST--
+stream filter - reading
+--FILE--
+<?php
+echo "-TEST\n";
+class filter extends php_user_filter {
+ function filter($in, $out, &$consumed, $closing)
+ {
+ $output = 0;
+ while ($bucket = stream_bucket_make_writeable($in)) {
+ $bucket->data = strtoupper($bucket->data);
+ $consumed += $bucket->datalen;
+ stream_bucket_append($out, $bucket);
+ $output = 1;
+ }
+ if ($closing) {
+ $bucket = stream_bucket_new($this->stream, "\n===close===\n");
+ stream_bucket_append($out, $bucket);
+ $output = 1;
+ }
+ return $output ? PSFS_PASS_ON : PSFS_FEED_ME;
+ }
+}
+stream_filter_register("strtoupper", "filter")
+ or die("Failed to register filter");
+
+if ($f = fopen(__FILE__, "rb")) {
+ stream_filter_append($f, "strtoupper");
+ while (!feof($f)) {
+ echo fread($f, 8192);
+ }
+ fclose($f);
+}
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+<?PHP
+ECHO "-TEST\N";
+CLASS FILTER EXTENDS PHP_USER_FILTER {
+ FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING)
+ {
+ $OUTPUT = 0;
+ WHILE ($BUCKET = STREAM_BUCKET_MAKE_WRITEABLE($IN)) {
+ $BUCKET->DATA = STRTOUPPER($BUCKET->DATA);
+ $CONSUMED += $BUCKET->DATALEN;
+ STREAM_BUCKET_APPEND($OUT, $BUCKET);
+ $OUTPUT = 1;
+ }
+ IF ($CLOSING) {
+ $BUCKET = STREAM_BUCKET_NEW($THIS->STREAM, "\N===CLOSE===\N");
+ STREAM_BUCKET_APPEND($OUT, $BUCKET);
+ $OUTPUT = 1;
+ }
+ RETURN $OUTPUT ? PSFS_PASS_ON : PSFS_FEED_ME;
+ }
+}
+STREAM_FILTER_REGISTER("STRTOUPPER", "FILTER")
+ OR DIE("FAILED TO REGISTER FILTER");
+
+IF ($F = FOPEN(__FILE__, "RB")) {
+ STREAM_FILTER_APPEND($F, "STRTOUPPER");
+ WHILE (!FEOF($F)) {
+ ECHO FREAD($F, 8192);
+ }
+ FCLOSE($F);
+}
+ECHO "DONE\N";
+?>
+
+===close===
+Done
diff --git a/main/streams/streams.c b/main/streams/streams.c
index de82eca4fe..af3deaa5c0 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -433,7 +433,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
/* allocate a buffer for reading chunks */
chunk_buf = emalloc(stream->chunk_size);
- while (!err_flag && (stream->writepos - stream->readpos < (off_t)size)) {
+ while (!stream->eof && !err_flag && (stream->writepos - stream->readpos < (off_t)size)) {
size_t justread = 0;
int flags;
php_stream_bucket *bucket;
@@ -442,7 +442,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
/* read a chunk into a bucket */
justread = stream->ops->read(stream, chunk_buf, stream->chunk_size TSRMLS_CC);
- if (justread != (size_t)-1) {
+ if (justread && justread != (size_t)-1) {
bucket = php_stream_bucket_new(stream, chunk_buf, justread, 0, 0 TSRMLS_CC);
/* after this call, bucket is owned by the brigade */