+
+
+memcached_return memcached_connect(memcached_st *ptr, unsigned int server_key)
+{
+ memcached_return rc= MEMCACHED_NO_SERVERS;
+ LIBMEMCACHED_MEMCACHED_CONNECT_START();
+
+ if (ptr->connected == ptr->number_of_hosts && ptr->number_of_hosts)
+ return MEMCACHED_SUCCESS;
+
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ return MEMCACHED_NO_SERVERS;
+
+ /* We need to clean up the multi startup piece */
+ switch (ptr->hosts[server_key].type)
+ {
+ case MEMCACHED_CONNECTION_UNKNOWN:
+ WATCHPOINT_ASSERT(0);
+ rc= MEMCACHED_NOT_SUPPORTED;
+ break;
+ case MEMCACHED_CONNECTION_UDP:
+ rc= udp_connect(ptr, server_key);
+ break;
+ case MEMCACHED_CONNECTION_TCP:
+ rc= tcp_connect(ptr, server_key);
+ break;
+ case MEMCACHED_CONNECTION_UNIX_SOCKET:
+ rc= unix_socket_connect(ptr, server_key);
+ break;
+ }
+
+ if (rc != MEMCACHED_SUCCESS)
+ WATCHPOINT_ERROR(rc);
+
+ LIBMEMCACHED_MEMCACHED_CONNECT_END();
+
+ return rc;
+}