X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fconnect.cc;h=52cd293a64c7b0827e79bc970c8dfb7e4d1fcdeb;hb=9b82636d0efe1ea990cd20eacd17c8b13a5b7743;hp=2e2dbf616fbe4fcb22f4fcc437f6fd17e947873b;hpb=cb3ca2b63f9ddb2e070814623a3965c88a84eea7;p=awesomized%2Flibmemcached diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 2e2dbf61..52cd293a 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -64,7 +64,7 @@ # define TCP_KEEPIDLE 0 #endif -static memcached_return_t connect_poll(org::libmemcached::Instance* server, const int connection_error) +static memcached_return_t connect_poll(memcached_instance_st* server, const int connection_error) { struct pollfd fds[1]; fds[0].fd= server->fd; @@ -76,7 +76,7 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server, cons if (server->root->poll_timeout == 0) { return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, - memcached_literal_param("The time to wait for a connection to be established was set to zero, which means it will always timeout (MEMCACHED_TIMEOUT).")); + memcached_literal_param("The time to wait for a connection to be established was set to zero which produces a timeout to every call to poll().")); } while (--loop_max) // Should only loop on cases of ERESTART or EINTR @@ -181,14 +181,15 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server, cons return memcached_set_errno(*server, connection_error, MEMCACHED_AT, memcached_literal_param("connect_poll() was exhausted")); } -static memcached_return_t set_hostinfo(org::libmemcached::Instance* server) +static memcached_return_t set_hostinfo(memcached_instance_st* server) { assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET); server->clear_addrinfo(); - char str_port[MEMCACHED_NI_MAXSERV]; + char str_port[MEMCACHED_NI_MAXSERV]= { 0 }; + errno= 0; int length= snprintf(str_port, MEMCACHED_NI_MAXSERV, "%u", uint32_t(server->port())); - if (length >= MEMCACHED_NI_MAXSERV or length <= 0) + if (length >= MEMCACHED_NI_MAXSERV or length <= 0 or errno != 0) { return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("snprintf(NI_MAXSERV)")); @@ -197,7 +198,7 @@ static memcached_return_t set_hostinfo(org::libmemcached::Instance* server) struct addrinfo hints; memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family= AF_INET; + hints.ai_family= AF_UNSPEC; if (memcached_is_udp(server->root)) { hints.ai_protocol= IPPROTO_UDP; @@ -245,7 +246,7 @@ static memcached_return_t set_hostinfo(org::libmemcached::Instance* server) return MEMCACHED_SUCCESS; } -static inline void set_socket_nonblocking(org::libmemcached::Instance* server) +static inline void set_socket_nonblocking(memcached_instance_st* server) { #if defined(_WIN32) u_long arg= 1; @@ -285,7 +286,7 @@ static inline void set_socket_nonblocking(org::libmemcached::Instance* server) #endif } -static bool set_socket_options(org::libmemcached::Instance* server) +static bool set_socket_options(memcached_instance_st* server) { assert_msg(server->fd != INVALID_SOCKET, "invalid socket was passed to set_socket_options()"); @@ -439,7 +440,7 @@ static bool set_socket_options(org::libmemcached::Instance* server) return true; } -static memcached_return_t unix_socket_connect(org::libmemcached::Instance* server) +static memcached_return_t unix_socket_connect(memcached_instance_st* server) { #ifndef _WIN32 WATCHPOINT_ASSERT(server->fd == INVALID_SOCKET); @@ -505,7 +506,7 @@ static memcached_return_t unix_socket_connect(org::libmemcached::Instance* serve #endif } -static memcached_return_t network_connect(org::libmemcached::Instance* server) +static memcached_return_t network_connect(memcached_instance_st* server) { bool timeout_error_occured= false; @@ -657,7 +658,7 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server) Based on time/failure count fail the connect without trying. This prevents waiting in a state where we get caught spending cycles just waiting. */ -static memcached_return_t backoff_handling(org::libmemcached::Instance* server, bool& in_timeout) +static memcached_return_t backoff_handling(memcached_instance_st* server, bool& in_timeout) { struct timeval curr_time; bool _gettime_success= (gettimeofday(&curr_time, NULL) == 0); @@ -712,6 +713,7 @@ static memcached_return_t backoff_handling(org::libmemcached::Instance* server, if (_gettime_success and server->next_retry < curr_time.tv_sec) { server->state= MEMCACHED_SERVER_STATE_NEW; + server->server_timeout_counter= 0; } else { @@ -724,7 +726,7 @@ static memcached_return_t backoff_handling(org::libmemcached::Instance* server, return MEMCACHED_SUCCESS; } -static memcached_return_t _memcached_connect(org::libmemcached::Instance* server, const bool set_last_disconnected) +static memcached_return_t _memcached_connect(memcached_instance_st* server, const bool set_last_disconnected) { assert(server); if (server->fd != INVALID_SOCKET) @@ -759,6 +761,7 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server case MEMCACHED_CONNECTION_TCP: rc= network_connect(server); +#if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) if (LIBMEMCACHED_WITH_SASL_SUPPORT) { if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks) @@ -771,6 +774,7 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server } } } +#endif break; case MEMCACHED_CONNECTION_UNIX_SOCKET: @@ -811,7 +815,7 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server return rc; } -memcached_return_t memcached_connect(org::libmemcached::Instance* server) +memcached_return_t memcached_connect(memcached_instance_st* server) { return _memcached_connect(server, true); }