+ e= getaddrinfo(server->hostname, str_port, &hints, &ai);
+ if (e != 0)
+ {
+ WATCHPOINT_STRING(server->hostname);
+ WATCHPOINT_STRING(gai_strerror(e));
+ return MEMCACHED_HOST_LOOKUP_FAILURE;
+ }
+
+ if (server->address_info)
+ freeaddrinfo(server->address_info);
+ server->address_info= ai;
+
+ return MEMCACHED_SUCCESS;
+}
+
+static memcached_return unix_socket_connect(memcached_st *ptr, unsigned int server_key)
+{
+ struct sockaddr_un servAddr;
+ socklen_t addrlen;
+
+ if (ptr->hosts[server_key].fd == -1)
+ {
+ if ((ptr->hosts[server_key].fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ ptr->cached_errno= errno;
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ }
+
+ memset(&servAddr, 0, sizeof (struct sockaddr_un));
+ servAddr.sun_family= AF_UNIX;
+ strcpy(servAddr.sun_path, ptr->hosts[server_key].hostname); /* Copy filename */
+
+ addrlen= strlen(servAddr.sun_path) + sizeof(servAddr.sun_family);
+
+test_connect:
+ if (connect(ptr->hosts[server_key].fd,
+ (struct sockaddr *)&servAddr,
+ sizeof(servAddr)) < 0)
+ {
+ switch (errno) {
+ /* We are spinning waiting on connect */
+ case EALREADY:
+ case EINPROGRESS:
+ case EINTR:
+ goto test_connect;
+ case EISCONN: /* We were spinning waiting on connect */
+ break;
+ default:
+ WATCHPOINT_ERRNO(errno);
+ ptr->cached_errno= errno;
+ return MEMCACHED_ERRNO;
+ }
+ ptr->connected++;
+ }
+ }
+ return MEMCACHED_SUCCESS;
+}
+
+static memcached_return udp_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);
+
+ /*
+ If we have not allocated the hosts object.
+ Or if the cache has not been set.
+ */
+ 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;