Fixed typo: SO_RCVBUF instead of SO_SNDBUF
[m6w6/libmemcached] / libmemcached / memcached_connect.c
index 57bce10107255bbef5c00a3506b6fd9c7a2a709d..753392b3f58e8a9e1f471da508e38b15b5cbbf8e 100644 (file)
@@ -46,9 +46,12 @@ static memcached_return set_hostinfo(memcached_server_st *server)
 
 static memcached_return set_socket_options(memcached_server_st *ptr)
 {
+  WATCHPOINT_ASSERT(ptr->fd != -1);
+
   if (ptr->type == MEMCACHED_CONNECTION_UDP)
     return MEMCACHED_SUCCESS;
 
+#ifdef HAVE_SNDTIMEO
   if (ptr->root->snd_timeout)
   {
     int error;
@@ -61,7 +64,9 @@ static memcached_return set_socket_options(memcached_server_st *ptr)
                       &waittime, (socklen_t)sizeof(struct timeval));
     WATCHPOINT_ASSERT(error == 0);
   }
+#endif
 
+#ifdef HAVE_RCVTIMEO
   if (ptr->root->rcv_timeout)
   {
     int error;
@@ -74,6 +79,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr)
                       &waittime, (socklen_t)sizeof(struct timeval));
     WATCHPOINT_ASSERT(error == 0);
   }
+#endif
 
   {
     int error;
@@ -109,7 +115,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr)
   {
     int error;
 
-    error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDBUF, 
+    error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVBUF, 
                       &ptr->root->recv_size, (socklen_t)sizeof(int));
     WATCHPOINT_ASSERT(error == 0);
   }
@@ -167,6 +173,8 @@ test_connect:
       }
     }
   }
+
+  WATCHPOINT_ASSERT(ptr->fd != -1);
   return MEMCACHED_SUCCESS;
 }
 
@@ -185,7 +193,7 @@ static memcached_return network_connect(memcached_server_st *ptr)
       }
     }
 
-    if (ptr->sockaddr_inited == MEMCACHED_NOT_ALLOCATED || 
+    if (ptr->sockaddr_inited || 
         (!(ptr->root->flags & MEM_USE_CACHE_LOOKUPS)))
     {
       memcached_return rc;
@@ -193,7 +201,7 @@ static memcached_return network_connect(memcached_server_st *ptr)
       rc= set_hostinfo(ptr);
       if (rc != MEMCACHED_SUCCESS)
         return rc;
-      ptr->sockaddr_inited= MEMCACHED_ALLOCATED;
+      ptr->sockaddr_inited= true;
     }
 
     use= ptr->address_info;
@@ -234,18 +242,12 @@ test_connect:
             {
               goto handle_retry;
             }
-            else if (error != 1 || fds[0].revents & POLLERR)
+            else if (error != 1 && fds[0].revents & POLLERR)
             {
               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;
-              }
+              memcached_quit_server(ptr, 1);
 
               if (ptr->root->retry_timeout)
               {
@@ -255,6 +257,7 @@ test_connect:
                 ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout;
               }
               ptr->server_failure_counter+= 1;
+
               return MEMCACHED_ERRNO;
             }