@@ -542,6 +542,9 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
542
542
{
543
543
/* allocate/fill the buffer */
544
544
545
+ zend_result retval ;
546
+ bool old_eof = stream -> eof ;
547
+
545
548
if (stream -> readfilters .head ) {
546
549
size_t to_read_now = MIN (size , stream -> chunk_size );
547
550
char * chunk_buf ;
@@ -562,7 +565,8 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
562
565
justread = stream -> ops -> read (stream , chunk_buf , stream -> chunk_size );
563
566
if (justread < 0 && stream -> writepos == stream -> readpos ) {
564
567
efree (chunk_buf );
565
- return FAILURE ;
568
+ retval = FAILURE ;
569
+ goto out_check_eof ;
566
570
} else if (justread > 0 ) {
567
571
bucket = php_stream_bucket_new (stream , chunk_buf , justread , 0 , 0 );
568
572
@@ -633,7 +637,8 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
633
637
* further reads should fail. */
634
638
stream -> eof = 1 ;
635
639
efree (chunk_buf );
636
- return FAILURE ;
640
+ retval = FAILURE ;
641
+ goto out_is_eof ;
637
642
}
638
643
639
644
if (justread <= 0 ) {
@@ -643,7 +648,6 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
643
648
644
649
efree (chunk_buf );
645
650
return SUCCESS ;
646
-
647
651
} else {
648
652
/* is there enough data in the buffer ? */
649
653
if (stream -> writepos - stream -> readpos < (zend_off_t )size ) {
@@ -670,12 +674,22 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t size)
670
674
stream -> readbuflen - stream -> writepos
671
675
);
672
676
if (justread < 0 ) {
673
- return FAILURE ;
677
+ retval = FAILURE ;
678
+ goto out_check_eof ;
674
679
}
675
680
stream -> writepos += justread ;
681
+ retval = SUCCESS ;
682
+ goto out_check_eof ;
676
683
}
677
684
return SUCCESS ;
678
685
}
686
+
687
+ out_check_eof :
688
+ if (old_eof != stream -> eof ) {
689
+ out_is_eof :
690
+ php_stream_notify_completed (PHP_STREAM_CONTEXT (stream ));
691
+ }
692
+ return retval ;
679
693
}
680
694
681
695
PHPAPI ssize_t _php_stream_read (php_stream * stream , char * buf , size_t size )
@@ -1124,6 +1138,7 @@ PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, con
1124
1138
static ssize_t _php_stream_write_buffer (php_stream * stream , const char * buf , size_t count )
1125
1139
{
1126
1140
ssize_t didwrite = 0 ;
1141
+ ssize_t retval ;
1127
1142
1128
1143
/* if we have a seekable stream we need to ensure that data is written at the
1129
1144
* current stream->position. This means invalidating the read buffer and then
@@ -1134,15 +1149,19 @@ static ssize_t _php_stream_write_buffer(php_stream *stream, const char *buf, siz
1134
1149
stream -> ops -> seek (stream , stream -> position , SEEK_SET , & stream -> position );
1135
1150
}
1136
1151
1152
+ bool old_eof = stream -> eof ;
1153
+
1137
1154
while (count > 0 ) {
1138
1155
ssize_t justwrote = stream -> ops -> write (stream , buf , count );
1139
1156
if (justwrote <= 0 ) {
1140
1157
/* If we already successfully wrote some bytes and a write error occurred
1141
1158
* later, report the successfully written bytes. */
1142
1159
if (didwrite == 0 ) {
1143
- return justwrote ;
1160
+ retval = justwrote ;
1161
+ goto out ;
1144
1162
}
1145
- return didwrite ;
1163
+ retval = didwrite ;
1164
+ goto out ;
1146
1165
}
1147
1166
1148
1167
buf += justwrote ;
@@ -1151,7 +1170,13 @@ static ssize_t _php_stream_write_buffer(php_stream *stream, const char *buf, siz
1151
1170
stream -> position += justwrote ;
1152
1171
}
1153
1172
1154
- return didwrite ;
1173
+ retval = didwrite ;
1174
+
1175
+ out :
1176
+ if (old_eof != stream -> eof ) {
1177
+ php_stream_notify_completed (PHP_STREAM_CONTEXT (stream ));
1178
+ }
1179
+ return retval ;
1155
1180
}
1156
1181
1157
1182
/* push some data through the write filter chain.
0 commit comments