Bad data for threads (Toru patch)
[m6w6/libmemcached] / libmemcached / memcached_connect.c
index 5531ad792d47175439d22c469138dbdb99575872..7d6f85a49840c99ed2c8be8114e38a5b030d0200 100644 (file)
@@ -207,13 +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;
             }
 
@@ -225,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)
@@ -285,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;