#35079 [Opn->Fbk]: stream_set_blocking(true) toggles, not enables blocking
| From: | sniper@php.net | Date: | Thu, 03 Nov 2005 14:48:12 +0000 |
| Subject: | #35079 [Opn->Fbk]: stream_set_blocking(true) toggles, not enables blocking | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87475@lists.php.net to get a copy of this message | ||
ID: 35079
Updated by: sniper@php.net
Reported By: askalski at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Filesystem function related
Operating System: linux
PHP Version: 5.0.5
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2005-11-03 05:55:11] askalski at gmail dot com
Description:
------------
main/streams/plain_wrapper.c (5.0.5)
main/streams.c (4.4 and earlier)
In several places, the ^= operator is used to turn off a flag. This is
incorrect. For example, stream_set_blocking() on a plain file hits this
code in php_stdiop_set_option():
if (value)
flags ^= O_NONBLOCK;
else
flags |= O_NONBLOCK;
This should be:
if (value)
flags &= ~O_NONBLOCK;
else
flags |= O_NONBLOCK;
The same error is repeated elsewhere in the code.
Reproduce code:
---------------
$fp = fopen("test", "w");
stream_set_blocking($fp, true);
stream_set_blocking($fp, true);
stream_set_blocking($fp, true);
stream_set_blocking($fp, true);
fclose($fp);
Expected result:
----------------
The stream should remain in blocking mode throughout the script
execution.
Actual result:
--------------
Here is abridged strace output showing the errant behavior. Notice how
O_NONBLOCK is being turned on and off alternately.
open("/home/askalski/test", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
fcntl64(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
fcntl64(4, F_SETFL, O_WRONLY) = 0
fcntl64(4, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
fcntl64(4, F_SETFL, O_WRONLY) = 0
close(4) = 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35079&edit=1