wez             Sun Dec 22 08:55:46 2002 EDT

  Modified files:              
    /php4/main  network.c 
  Log:
  A Simple fix for Bug #12360 (fsockopen timeout doesn't work).
  
  Analysis:
  On systems with HAVE_GETADDRINFO and IPV6 support, php_hostconnect would
  attempt to connect to each possible address that matched the requested IP.
  
  If the remote host:port combination are dropping packets this would cause the
  first connection to timeout (after waiting for the full timeout duration).
  
  PHP would then attempt the second address and wait the full duration again.
  
  Solution:
  If the first connection attempt times out, abort the connection loop.
  
  
  
Index: php4/main/network.c
diff -u php4/main/network.c:1.83 php4/main/network.c:1.84
--- php4/main/network.c:1.83    Tue Oct 29 09:57:12 2002
+++ php4/main/network.c Sun Dec 22 08:55:45 2002
@@ -16,7 +16,7 @@
    | Streams work by Wez Furlong <[EMAIL PROTECTED]>                   |
    +----------------------------------------------------------------------+
  */
-/* $Id: network.c,v 1.83 2002/10/29 14:57:12 wez Exp $ */
+/* $Id: network.c,v 1.84 2002/12/22 13:55:45 wez Exp $ */
 
 /*#define DEBUG_MAIN_NETWORK 1*/
 
@@ -100,9 +100,11 @@
 #ifdef PHP_WIN32
 # define SOCK_ERR INVALID_SOCKET
 # define SOCK_CONN_ERR SOCKET_ERROR
+# define PHP_TIMEOUT_ERROR_VALUE               WSAETIMEDOUT
 #else
 # define SOCK_ERR -1
 # define SOCK_CONN_ERR -1
+# define PHP_TIMEOUT_ERROR_VALUE               ETIMEDOUT
 #endif
 
 #ifdef HAVE_GETADDRINFO
@@ -266,6 +268,7 @@
        int ret = 0;
        fd_set rset;
        fd_set wset;
+       fd_set eset;
 
        if (timeout == NULL)    {
                /* blocking mode */
@@ -286,11 +289,13 @@
        }
 
        FD_ZERO(&rset);
+       FD_ZERO(&eset);
        FD_SET(sockfd, &rset);
+       FD_SET(sockfd, &eset);
 
        wset = rset;
 
-       if ((n = select(sockfd + 1, &rset, &wset, NULL, timeout)) == 0) {
+       if ((n = select(sockfd + 1, &rset, &wset, &eset, timeout)) == 0) {
                error = ETIMEDOUT;
        }
 
@@ -400,9 +405,7 @@
        struct sockaddr **sal, **psal;
        struct timeval individual_timeout;
        int set_timeout = 0;
-#ifdef PHP_WIN32
        int err;
-#endif
        
        n = php_network_getaddresses(host, &sal TSRMLS_CC);
 
@@ -463,10 +466,19 @@
 #ifdef PHP_WIN32
                        /* Preserve the last error */
                        err = WSAGetLastError();
+#else
+                       err = errno;
 #endif
                        close (s);
                }
                sal++;
+
+               if (err == PHP_TIMEOUT_ERROR_VALUE) {
+                       /* if the first attempt timed out, it's highly likely
+                        * that any subsequent attempts will do so also */
+                       break;
+               }
+               
        }
        php_network_freeaddresses(psal);
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_hostconnect: connect failed");



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to