PHP 4.0 Bug #7073: socket_set_timeout results in incorrect socket timeouts

From: Date: Fri, 06 Oct 2000 20:41:33 +0000
Subject: PHP 4.0 Bug #7073: socket_set_timeout results in incorrect socket timeouts
Groups: php.dev 
Request: Send a blank email to php-dev+get-34405@lists.php.net to get a copy of this message
From: tcarroll@chc-chimes.com Operating system: FreeBSD 4.1 PHP version: 4.0.2 PHP Bug Type: Sockets related Bug description: socket_set_timeout results in incorrect socket timeouts 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=

« previous php.dev (#34405) next »