php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7073 socket_set_timeout results in incorrect socket timeouts
Submitted: 2000-10-06 16:41 UTC Modified: 2000-10-09 10:48 UTC
From: tcarroll at chc-chimes dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.2 OS: FreeBSD 4.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tcarroll at chc-chimes dot com
New email:
PHP Version: OS:

 

 [2000-10-06 16:41 UTC] tcarroll at chc-chimes dot 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;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-09 09:31 UTC] andrei@php.net
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.

 [2000-10-09 10:48 UTC] tcarroll at chc-chimes dot com
My bad.  Set me straight
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC