Fixes build on FreeBSD.
[m6w6/libmemcached] / libmemcached / connect.c
index 96f26fb80e07f6116435eb4ef9259f4d9db14134..f3832faed079d8b771ee18e61b1237b7a8283c5e 100644 (file)
@@ -111,7 +111,7 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr)
       return MEMCACHED_FAILURE;
   }
 
-  if (ptr->root->send_size)
+  if (ptr->root->send_size > 0)
   {
     int error;
 
@@ -122,7 +122,7 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr)
       return MEMCACHED_FAILURE;
   }
 
-  if (ptr->root->recv_size)
+  if (ptr->root->recv_size > 0)
   {
     int error;
 
@@ -208,7 +208,9 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
   {
     struct addrinfo *use;
 
-    if (!ptr->sockaddr_inited ||
+    WATCHPOINT_ASSERT(ptr->cursor_active == 0);
+
+    if (! ptr->options.sockaddr_inited ||
         (!(ptr->root->flags.use_cache_lookups)))
     {
       memcached_return_t rc;
@@ -216,7 +218,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
       rc= set_hostinfo(ptr);
       if (rc != MEMCACHED_SUCCESS)
         return rc;
-      ptr->sockaddr_inited= true;
+      ptr->options.sockaddr_inited= true;
     }
 
     use= ptr->address_info;
@@ -280,9 +282,22 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
         }
       }
 
+#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+      if (ptr->fd != -1 && ptr->root->sasl.callbacks != NULL)
+      {
+        memcached_return rc= memcached_sasl_authenticate_connection(ptr);
+        if (rc != MEMCACHED_SUCCESS)
+        {
+          (void)close(ptr->fd);
+          ptr->fd= -1;
+          return rc;
+        }
+      }
+#endif
+
+
       if (ptr->fd != -1)
       {
-        WATCHPOINT_ASSERT(ptr->cursor_active == 0);
         ptr->server_failure_counter= 0;
         return MEMCACHED_SUCCESS;
       }
@@ -312,7 +327,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr)
 }
 
 
-memcached_return_t memcached_connect(memcached_server_st *ptr)
+memcached_return_t memcached_connect(memcached_server_write_instance_st ptr)
 {
   memcached_return_t rc= MEMCACHED_NO_SERVERS;
   LIBMEMCACHED_MEMCACHED_CONNECT_START();
@@ -334,12 +349,16 @@ memcached_return_t memcached_connect(memcached_server_st *ptr)
 
     if (curr_time.tv_sec < ptr->next_retry)
     {
-      if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
+      memcached_st *root= (memcached_st *)ptr->root;
+      // @todo fix this by fixing behavior to no longer make use of
+      // memcached_st
+      if (memcached_behavior_get(root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
       {
-        run_distribution(ptr->root);
+        run_distribution(root);
       }
 
-      ptr->root->last_disconnected_server = ptr;
+      root->last_disconnected_server = ptr;
+
       return MEMCACHED_SERVER_MARKED_DEAD;
     }
   }
@@ -363,7 +382,12 @@ memcached_return_t memcached_connect(memcached_server_st *ptr)
     WATCHPOINT_ASSERT(0);
   }
 
-  unlikely ( rc != MEMCACHED_SUCCESS) ptr->root->last_disconnected_server = ptr;
+  unlikely ( rc != MEMCACHED_SUCCESS)
+  {
+    //@todo create interface around last_discontected_server
+    memcached_st *root= (memcached_st *)ptr->root;
+    root->last_disconnected_server = ptr;
+  }
 
   LIBMEMCACHED_MEMCACHED_CONNECT_END();