ID: 47289
Updated by: [email protected]
Reported By: patryk dot szczyglowski at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: Linux 2.6
PHP Version: 5.2.8
New Comment:
There is no loop in the code, how would it get stuck unless you are
doing while(socket_read()) ?
Previous Comments:
------------------------------------------------------------------------
[2009-02-03 15:44:28] patryk dot szczyglowski at gmail dot com
Description:
------------
When PHP wants to read from a blocking socket when the remote host
disconnects, PHP ignores 0 return code from recv() system function and
drops into endless loop.
Reproduce code:
---------------
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $ip, $port);
// disconnect remote host here
$rcv = socket_read($this->socket, 65536, PHP_BINARY_READ); // this line
never returns
Expected result:
----------------
socket_read returns with FALSE
--- php-5.2.8/ext/sockets/sockets.c.orig 2008-10-23 22:21:30.000000000
+0200
+++ php-5.2.8/ext/sockets/sockets.c 2009-01-29 17:32:53.000000000
+0100
@@ -903,6 +903,14 @@
RETURN_FALSE;
}
+ if (retval == 0) {
+ php_sock->error = errno;
+ SOCKETS_G(last_error) = errno;
+
+ efree(tmpbuf);
+ RETURN_FALSE;
+ }
+
tmpbuf = erealloc(tmpbuf, retval + 1);
tmpbuf[retval] = '\0' ;
Actual result:
--------------
socket_read never returns, it gets looped in ext/sockets/sockets.c:885
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47289&edit=1