+ memcached_return rc;
+
+ rc= set_hostinfo(&ptr->hosts[server_key]);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+
+ ptr->hosts[server_key].sockaddr_inited= MEMCACHED_ALLOCATED;
+ }
+
+ /* Create the socket */
+ if ((ptr->hosts[server_key].fd= socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ {
+ ptr->cached_errno= errno;
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ }
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
+static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key)
+{
+ if (ptr->hosts[server_key].fd == -1)
+ {
+ /* Old connection junk still is in the structure */
+ WATCHPOINT_ASSERT(ptr->hosts[server_key].cursor_active == 0);
+ struct addrinfo *use;
+
+ if (ptr->hosts[server_key].sockaddr_inited == MEMCACHED_NOT_ALLOCATED ||
+ (!(ptr->flags & MEM_USE_CACHE_LOOKUPS)))
+ {
+ memcached_return rc;
+
+ rc= set_hostinfo(&ptr->hosts[server_key]);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+ ptr->hosts[server_key].sockaddr_inited= MEMCACHED_ALLOCATED;
+ }
+ use= ptr->hosts[server_key].address_info;
+
+ /* Create the socket */
+ if ((ptr->hosts[server_key].fd= socket(use->ai_family,
+ use->ai_socktype,
+ use->ai_protocol)) < 0)
+ {
+ ptr->cached_errno= errno;
+ WATCHPOINT_ERRNO(errno);
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ }
+
+ if (ptr->flags & MEM_NO_BLOCK)
+ {
+ int error;
+ struct linger linger;
+ struct timeval waittime;