var_dump(stream_set_chunk_size($f, 1));
echo "should be read without buffer (\$count == 10000)\n";
var_dump(strlen(fread($f, 10000)));
-echo "should elicit 3 writes of size 1 and return 3\n";
+echo "should have no effect on writes\n";
var_dump(fwrite($f, str_repeat('b', 3)));
echo "should return previous chunk size (1)\n";
var_dump(strlen(fread($f, 50)));
echo "should elicit no read because there is sufficient cached data\n";
var_dump(strlen(fread($f, 50)));
-echo "should elicit 2 writes of size 100 and one of size 50\n";
+echo "should have no effect on writes\n";
var_dump(strlen(fwrite($f, str_repeat('b', 250))));
echo "\nerror conditions\n";
should be read without buffer ($count == 10000)
read with size: 10000
int(10000)
-should elicit 3 writes of size 1 and return 3
-write with size: 1
-write with size: 1
-write with size: 1
+should have no effect on writes
+write with size: 3
int(3)
should return previous chunk size (1)
int(1)
int(50)
should elicit no read because there is sufficient cached data
int(50)
-should elicit 2 writes of size 100 and one of size 50
-write with size: 100
-write with size: 100
-write with size: 50
+should have no effect on writes
+write with size: 250
int(3)
error conditions
/* Writes a buffer directly to a stream, using multiple of the chunk size */
static ssize_t _php_stream_write_buffer(php_stream *stream, const char *buf, size_t count)
{
- ssize_t didwrite = 0, justwrote;
+ ssize_t didwrite = 0;
/* if we have a seekable stream we need to ensure that data is written at the
* current stream->position. This means invalidating the read buffer and then
stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position);
}
-
while (count > 0) {
- size_t towrite = count;
- if (towrite > stream->chunk_size)
- towrite = stream->chunk_size;
-
- justwrote = stream->ops->write(stream, buf, towrite);
+ ssize_t justwrote = stream->ops->write(stream, buf, count);
if (justwrote <= 0) {
/* If we already successfully wrote some bytes and a write error occurred
* later, report the successfully written bytes. */