Bad data for threads (Toru patch)
[m6w6/libmemcached] / libmemcached / memcached_connect.c
index ab4b84f0936d588cac7fe7671d25647742727809..7d6f85a49840c99ed2c8be8114e38a5b030d0200 100644 (file)
@@ -1,5 +1,6 @@
 #include "common.h"
 #include <poll.h>
+#include <sys/time.h>
 
 static memcached_return set_hostinfo(memcached_server_st *server)
 {
@@ -206,12 +207,23 @@ test_connect:
             fds[0].events= POLLOUT |  POLLERR;
             error= poll(fds, 1, ptr->root->connect_timeout);
 
-            if (error != 1)
+            if (error == 0) 
+            {
+              goto handle_retry;
+            }
+            else if (error != 1)
             {
               ptr->cached_errno= errno;
               WATCHPOINT_ERRNO(ptr->cached_errno);
+              WATCHPOINT_NUMBER(ptr->root->connect_timeout);
               close(ptr->fd);
               ptr->fd= -1;
+              if (ptr->address_info)
+              {
+                freeaddrinfo(ptr->address_info);
+                ptr->address_info= NULL;
+              }
+
               return MEMCACHED_ERRNO;
             }
 
@@ -223,8 +235,8 @@ test_connect:
         case EISCONN: /* We were spinning waiting on connect */
           break;
         default:
+handle_retry:
           ptr->cached_errno= errno;
-          WATCHPOINT_ERRNO(ptr->cached_errno);
           close(ptr->fd);
           ptr->fd= -1;
           if (ptr->root->retry_timeout)
@@ -283,9 +295,6 @@ memcached_return memcached_connect(memcached_server_st *ptr)
     WATCHPOINT_ASSERT(0);
   }
 
-  if (rc != MEMCACHED_SUCCESS)
-    WATCHPOINT_ERROR(rc);
-
   LIBMEMCACHED_MEMCACHED_CONNECT_END();
 
   return rc;