From:             [EMAIL PROTECTED]
Operating system: Linux RedHat 7.0 Kernel 2.2.17-8
PHP version:      4.0.4pl1
PHP Bug Type:     Sockets related
Bug description:  Socket reading functions always timeout

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 Bug report at: http://bugs.php.net/?id=10001&edit=1



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to