From: Brian Aker Date: Fri, 20 May 2011 06:07:09 +0000 (-0700) Subject: Cleanup the lookup code. X-Git-Tag: 0.51~10^2~9 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d676720d31be78bad7a986b2ead885d2e3ecc27b;p=m6w6%2Flibmemcached Cleanup the lookup code. --- diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 26e2f18a..1d95fd45 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -145,52 +145,33 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) hints.ai_protocol= IPPROTO_TCP; } - uint32_t counter= 5; - while (--counter) + int errcode; + switch(errcode= getaddrinfo(server->hostname, str_port, &hints, &server->address_info)) { - int errcode; - switch(errcode= getaddrinfo(server->hostname, str_port, &hints, &server->address_info)) - { - case 0: - break; - case EAI_AGAIN: - if (counter > 1) - { -#ifndef WIN32 - struct timespec dream, rem; + case 0: + break; - dream.tv_nsec= 1000; - dream.tv_sec= 0; + case EAI_AGAIN: + return memcached_set_error_string(*server, MEMCACHED_TIMEOUT, gai_strerror(errcode), strlen(gai_strerror(errcode))); - nanosleep(&dream, &rem); -#endif - continue; - } - else - { - return memcached_set_error_string(*server, MEMCACHED_HOST_LOOKUP_FAILURE, gai_strerror(errcode), strlen(gai_strerror(errcode))); - } - - case EAI_SYSTEM: - { - static memcached_string_t mesg= { memcached_literal_param("getaddrinfo") }; - return memcached_set_errno(*server, errno, &mesg); - } - case EAI_BADFLAGS: - return memcached_set_error_string(*server, MEMCACHED_HOST_LOOKUP_FAILURE, memcached_literal_param("getaddrinfo(EAI_BADFLAGS)")); + case EAI_SYSTEM: + { + static memcached_string_t mesg= { memcached_literal_param("getaddrinfo") }; + return memcached_set_errno(*server, errno, &mesg); + } + case EAI_BADFLAGS: + return memcached_set_error_string(*server, MEMCACHED_INVALID_ARGUMENTS, memcached_literal_param("getaddrinfo(EAI_BADFLAGS)")); - case EAI_MEMORY: - return memcached_set_error_string(*server, MEMCACHED_ERRNO, memcached_literal_param("getaddrinfo(EAI_MEMORY)")); + case EAI_MEMORY: + return memcached_set_error_string(*server, MEMCACHED_ERRNO, memcached_literal_param("getaddrinfo(EAI_MEMORY)")); - default: - { - WATCHPOINT_STRING(server->hostname); - WATCHPOINT_STRING(gai_strerror(e)); - return memcached_set_error_string(*server, MEMCACHED_HOST_LOOKUP_FAILURE, gai_strerror(errcode), strlen(gai_strerror(errcode))); - } + default: + { + WATCHPOINT_STRING(server->hostname); + WATCHPOINT_STRING(gai_strerror(e)); + return memcached_set_error_string(*server, MEMCACHED_HOST_LOOKUP_FAILURE, gai_strerror(errcode), strlen(gai_strerror(errcode))); } } - server->address_info_next= server->address_info; return MEMCACHED_SUCCESS; @@ -423,10 +404,26 @@ static memcached_return_t network_connect(memcached_server_st *ptr) WATCHPOINT_ASSERT(ptr->fd == INVALID_SOCKET); WATCHPOINT_ASSERT(ptr->cursor_active == 0); - if (! ptr->address_info) + if (not ptr->address_info) { - memcached_return_t rc= set_hostinfo(ptr); - if (rc != MEMCACHED_SUCCESS) + memcached_return_t rc; + uint32_t counter= 5; + while (--counter) + { + if ((rc= set_hostinfo(ptr)) != MEMCACHED_TIMEOUT) + break; + +#ifndef WIN32 + struct timespec dream, rem; + + dream.tv_nsec= 1000; + dream.tv_sec= 0; + + nanosleep(&dream, &rem); +#endif + } + + if (memcached_failed(rc)) return rc; }