PHP 4.0 Bug #7073 Updated: socket_set_timeout results in incorrect socket timeouts
| From: | Bug Database | Date: | Mon, 09 Oct 2000 13:31:44 +0000 |
| Subject: | PHP 4.0 Bug #7073 Updated: socket_set_timeout results in incorrect socket timeouts | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34501@lists.php.net to get a copy of this message | ||
ID: 7073
Updated by: andrei
Reported By: tcarroll@chc-chimes.com
Status: Closed
Bug Type: Sockets related
Assigned To:
Comments:
You are not correct. ptimeout gets set to either NULL or the address of timeout structure. The
timeout structure is then assigned the value of passed timeout inside the loop so ptimeout _is_ set
as well. This is necessary because on Linux the value of ptimeout will be undefined after select()
returns.
Previous Comments:
---------------------------------------------------------------------------
[2000-10-06 16:41:33] tcarroll@chc-chimes.com
The following script illustrates the problem.
//open some $sock
socket_set_timeout( $sock, 45 );
if(!($ret = fread( $sock, 255 )) {
//Happens randomly
$status = socket_get_status( $sock );
if( $status['timeout'] )
echo 'I timed out!';
}
The problem is in php_sockwait_for_data:ext/standard/file.c
If a timeout is set, ptimeout is equated to a non-initialized variable.
This explains the random timeout behavior
a diff follow of fsock.c follows:
--- /home/tcarroll/cvs-php/php4/ext/standard/fsock.c Sun Aug 27 00:14:47 2000
+++/home/tcarroll/php-4.0.2/ext/standard/fsock.c Fri Oct 6 16:14:22 2000
@@ -493,9 +493,9 @@
static void php_sockwait_for_data(php_sockbuf *sock)
{
- fd_set fdr, tfdr;
+ fd_set fdr;
int retval;
- struct timeval timeout, *ptimeout;
+ struct timeval *ptimeout;
FD_ZERO(&fdr);
FD_SET(sock->socket, &fdr);
@@ -504,13 +504,10 @@
if (sock->timeout.tv_sec == -1)
ptimeout = NULL;
else
- ptimeout = &timeout;
+ ptimeout = &sock->timeout;
while(1) {
- tfdr = fdr;
- timeout = sock->timeout;
-
- retval = select(sock->socket + 1, &tfdr, NULL, NULL, ptimeout);
+ retval = select(sock->socket + 1, &fdr, NULL, NULL, ptimeout);
if (retval == 0)
sock->timeout_event = 1;
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=7073