php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41371 stream_set_blocking bug with sockets
Submitted: 2007-05-12 00:49 UTC Modified: 2007-07-17 13:29 UTC
From: six at aegis-corp dot org Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.2 OS: Linux 2.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: six at aegis-corp dot org
New email:
PHP Version: OS:

 

 [2007-05-12 00:49 UTC] six at aegis-corp dot org
Description:
------------
When a stream has been obtained using stream_socket_accept from a non-blocking server, php believes that it is itself non-blocking and refuses to set it non blocking after a call to stream_set_blocking.

Reproduce code:
---------------
<?

$s = stream_socket_server("tcp://0.0.0.0:12345");
stream_set_blocking($s, false);

$c = stream_socket_accept($s);

// code will work if uncommented
//stream_set_blocking($c, true);

stream_set_blocking($c, false);

?>

Expected result:
----------------
Expected result is that $c is non-blocking, which it is *not* unless the previous stream_set_blocking($c, true) is uncommented (this may reset some internal cache ?)

Actual result:
--------------
reproduce code strace:

listen(3, 5)                            = 0
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 60000) = 1
accept(3, {sa_family=AF_INET, sin_port=htons(58901), sin_addr=inet_addr("127.0.0.1")}, [16]) = 4
[stream_set_blocking($c, false) does nothing here]
close(4)                                = 0
close(3)                                = 0
[script ends]

reproduce code strace with second call uncommented :

listen(3, 5)                            = 0
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP, revents=POLLIN}], 1, 60000) = 1
accept(3, {sa_family=AF_INET, sin_port=htons(58901), sin_addr=inet_addr("127.0.0.1")}, [16]) = 4
fcntl64(4, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(4, F_SETFL, O_RDWR)             = 0
fcntl64(4, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(4, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
[the two stream_set_blocking calls work here]
close(4)                                = 0
close(3)                                = 0
[script ends]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-13 21:42 UTC] sniper@php.net
This works just fine for me without having 2 stream_set_blocking() calls. Are you sure you're using PHP 5.2.2? And is that strace from exactly that script you pasted here? And what was the configure line used to configure PHP?
 [2007-05-13 22:05 UTC] sniper@php.net
And note: fctnl() is called only when needed in the streams code.
(if stream is already blocked -> fcntl won't be called at all)


 [2007-05-13 23:43 UTC] sniper@php.net
And that's exactly the reason for this bug. :D
 [2007-07-17 13:29 UTC] jani@php.net
This bug has been fixed in CVS.

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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 30 19:01:29 2025 UTC