Bug #51854 [Opn->Csd]: stream_set_read_buffer() not working as expected

From: Date: Tue, 18 May 2010 19:40:25 +0000
Subject: Bug #51854 [Opn->Csd]: stream_set_read_buffer() not working as expected
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150577@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51854&edit=1

 ID:               51854
 Updated by:       pajoye@php.net
 Reported by:      datibbaw@php.net
 Summary:          stream_set_read_buffer() not working as expected
-Status:           Open
+Status:           Closed
 Type:             Bug
 Package:          Streams related
-Operating System: Linux
+Operating System: *
 PHP Version:      Irrelevant
-Assigned To:      
+Assigned To:      pajoye

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2010-05-18 21:39:41] pajoye@php.net

Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=299466
Log: - #51854, fix logic (patch by Tjerk)

------------------------------------------------------------------------
[2010-05-18 19:57:36] datibbaw@php.net

Description:
------------
Recently, the stream_set_read_buffer() was introduced; it's signature
suggests that a buffer size can be set.

However, when passing any non-zero value, the stream becomes
unbuffered.

This is because of a missing check inside _php_stream_set_option():

if (value == PHP_STREAM_BUFFER_NONE) {
    stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
} else {
    stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER;
}

Test script:
---------------
<?php

$f = fopen('/dev/urandom', 'rb');
// setting read buffer to 1024
stream_set_read_buffer($f, 1024);
// reading the first 10 bytes
$s = fread($f, 10);
fclose($f);

/*
========= STRACE OUTPUT =========

open("/dev/urandom", O_RDONLY)          = 3
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "\3X\264\rQ\277\273\367\347Z", 10) = 10
close(3)                                = 0
*/
?>

Expected result:
----------------
Either the read() loads 1024 bytes, which would be ideal, or it should
still load the default buffer size (8192 bytes).

The attached patch addresses the latter behaviour.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51854&edit=1


Thread (2 messages)

« previous php.bugs (#150577) next »