Bug #10001 Updated: Socket reading functions always timeout

From: Date: Mon, 18 Mar 2002 20:18:44 +0000
Subject: Bug #10001 Updated: Socket reading functions always timeout
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-2792@lists.php.net to get a copy of this message
ID: 10001 Updated by: wez@php.net Reported By: chris@greatbridge.com -Status: Open +Status: Closed Bug Type: Sockets related Operating System: Linux RedHat 7.0 Kernel 2.2.17-8 PHP Version: 4.0.4pl1 New Comment: This bug has been fixed in CVS. Previous Comments: ------------------------------------------------------------------------ [2001-03-26 13:35:47] chris@greatbridge.com While performing read functions on a socket, fread,fgets,fgetss, with the timeout value set on the socket If a timeout occurs all subsequent calls timeout immediately. example: $s = fsockopen("localhost",25); socket_set_timeout($s,0,100000); $rply = fgets($s,129); # "220 server.domain SMTP server xyz v1.0" fputs($s,"HELO my.domain\r\n"); $rply = fgets($s,129); # "250 Welcom my.domain" $rply = fgets($s,129); # no data so it times out fputs($s,"NOOP\r\n"); $rply = fgets($s,129); # times out; data is available fputs($s,"QUIT\r\n"); $rply = fgets($s,129); # times out; data is available fclose($s); Removing the fgets that doesn't get any data will cause the program to run as expected. Also, moving the fgets to any line will cause all lines below it to timeout even when there is data. I tracked the the problem down in ext/standard/fclose.c to being while loops that use the sock->timeout_event variable as a condition without first reseting the variable to an appropiate value. Below is a context diff that fixes the problem. *** /usr/local/src/php-4.0.4pl1/ext/standard/fsock.c.old Mon Mar 26 13:07:40 2001 --- /usr/local/src/php-4.0.4pl1/ext/standard/fsock.c Mon Mar 26 13:12:03 2001 *************** *** 559,564 **** --- 559,565 ---- static void php_sockread_total(php_sockbuf *sock, size_t maxread) { + sock->timeout_event = 0; while(!sock->eof && TOREAD(sock) < maxread && !sock->timeout_event) { php_sockread_internal(sock); } *************** *** 619,624 **** --- 620,627 ---- } SEARCHCR(); + + sock->timeout_event = 0; if(!p) { if(sock->is_blocked) { ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=10001&edit=1

« previous php.bugs (#2792) next »