X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_connect.c;h=1a7cde1676dc2e536607fe5547f9d8637f0db6ab;hb=0104faa2803775d4f1b2c1115f4b6a8025252041;hp=cbf57fdc6607e19a1b5bcf24188d8b0bafb8dcf5;hpb=3bcf5c0efffbf64b6b6eccf140f057d2373fa974;p=m6w6%2Flibmemcached diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index cbf57fdc..1a7cde16 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -10,14 +10,31 @@ static memcached_return set_hostinfo(memcached_server_st *server) { struct hostent *h; - +#ifdef HAVE_GETHOSTBYNAME_R + struct hostent h_static; + char buffer[SMALL_STRING_LEN]; + int tmp_error; + + if (gethostbyname_r(server->hostname, + &h_static, buffer, SMALL_STRING_LEN, + &h, &tmp_error)) + { + WATCHPOINT_STRING(server->hostname); + WATCHPOINT_STRING(hstrerror(tmp_error)); + return MEMCACHED_HOST_LOOKUP_FAILURE; + } +#else if ((h= gethostbyname(server->hostname)) == NULL) { - return MEMCACHED_HOST_LOCKUP_FAILURE; + WATCHPOINT_STRING(server->hostname); + WATCHPOINT_STRING(hstrerror(h_errno)); + return MEMCACHED_HOST_LOOKUP_FAILURE; } +#endif server->servAddr.sin_family= h->h_addrtype; memcpy((char *) &server->servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length); + server->servAddr.sin_port = htons(server->port); return MEMCACHED_SUCCESS; @@ -72,13 +89,20 @@ static memcached_return udp_connect(memcached_st *ptr, unsigned int server_key) /* Old connection junk still is in the structure */ WATCHPOINT_ASSERT(ptr->hosts[server_key].stack_responses == 0); - if (ptr->hosts[server_key].servAddr.sin_family == 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; + + ptr->hosts[server_key].sockaddr_inited= MEMCACHED_ALLOCATED; } /* Create the socket */ @@ -203,6 +227,9 @@ memcached_return memcached_connect(memcached_st *ptr, unsigned int server_key) rc= unix_socket_connect(ptr, server_key); break; } + + if (rc != MEMCACHED_SUCCESS) + WATCHPOINT_ERROR(rc); } else { @@ -233,7 +260,10 @@ memcached_return memcached_connect(memcached_st *ptr, unsigned int server_key) rc= MEMCACHED_SUCCESS; if (possible_rc != MEMCACHED_SUCCESS) + { + WATCHPOINT_ERROR(possible_rc); rc= MEMCACHED_SOME_ERRORS; + } } } LIBMEMCACHED_MEMCACHED_CONNECT_END();