+ 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].stack_responses == 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;
+
+ linger.l_onoff= 1;
+ linger.l_linger= MEMCACHED_DEFAULT_TIMEOUT;
+ error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_LINGER,
+ &linger, (socklen_t)sizeof(struct linger));
+ WATCHPOINT_ASSERT(error == 0);
+ }
+
+ if (ptr->flags & MEM_TCP_NODELAY)
+ {
+ int flag= 1;
+ int error;
+
+ error= setsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, TCP_NODELAY,
+ &flag, (socklen_t)sizeof(int));
+ WATCHPOINT_ASSERT(error == 0);
+ }
+
+ if (ptr->send_size)
+ {
+ int error;
+
+ error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF,
+ &ptr->send_size, (socklen_t)sizeof(int));
+ WATCHPOINT_ASSERT(error == 0);
+ }
+
+ if (ptr->recv_size)
+ {
+ int error;
+
+ error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF,
+ &ptr->recv_size, (socklen_t)sizeof(int));
+ WATCHPOINT_ASSERT(error == 0);
+ }
+
+ /* For the moment, not getting a nonblocking mode will not be fatal */
+ if (ptr->flags & MEM_NO_BLOCK)
+ {
+ int flags;
+
+ flags= fcntl(ptr->hosts[server_key].fd, F_GETFL, 0);
+ if (flags != -1)