+
+
+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 */
+ if (server_key)
+ {
+ rc= tcp_connect(ptr, server_key);
+ 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;
+ }
+ }
+ else
+ {
+ unsigned int x;
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ memcached_return possible_rc;
+
+ possible_rc= MEMCACHED_NOT_SUPPORTED; /* Remove warning */
+
+ switch (ptr->hosts[x].type)
+ {
+ case MEMCACHED_CONNECTION_UNKNOWN:
+ WATCHPOINT_ASSERT(0);
+ possible_rc= MEMCACHED_NOT_SUPPORTED;
+ break;
+ case MEMCACHED_CONNECTION_UDP:
+ possible_rc= udp_connect(ptr, x);
+ break;
+ case MEMCACHED_CONNECTION_TCP:
+ possible_rc= tcp_connect(ptr, x);
+ break;
+ case MEMCACHED_CONNECTION_UNIX_SOCKET:
+ possible_rc= unix_socket_connect(ptr, x);
+ break;
+ }
+ rc= MEMCACHED_SUCCESS;
+
+ if (possible_rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+ }
+ }
+ LIBMEMCACHED_MEMCACHED_CONNECT_END();
+
+ return rc;
+}