+
+
+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)
+ return MEMCACHED_SUCCESS;
+
+ if (!ptr->hosts)
+ return MEMCACHED_NO_SERVERS;
+
+ /* We need to clean up the multi startup piece */
+ if (server_key)
+ rc= memcached_real_connect(ptr, server_key);
+ else
+ {
+ unsigned int x;
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ memcached_return possible_rc;
+
+ possible_rc= memcached_real_connect(ptr, x);
+ rc= MEMCACHED_SUCCESS;
+
+ if (possible_rc != MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SOME_ERRORS;
+ }
+ }
+ LIBMEMCACHED_MEMCACHED_CONNECT_END();
+
+ return rc;
+}