X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fconnect.cc;h=2de01494eae5476a7b2860a38ff74d2e734cf14b;hb=61b948a92ab79734b009a438b5cf3bfad03cb59d;hp=659d34078ce2f168523186b447c4ba6db4775cba;hpb=159d85141f157810f5a7d388658fc6923067041e;p=awesomized%2Flibmemcached diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 659d3407..2de01494 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -76,7 +76,7 @@ static memcached_return_t connect_poll(memcached_instance_st* server, const int 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 @@ -146,7 +146,7 @@ static memcached_return_t connect_poll(memcached_instance_st* server, const int return memcached_set_errno(*server, errno, MEMCACHED_AT, memcached_literal_param("getsockopt() errored while looking up error state from poll()")); } - // We check the value to see what happened wth the socket. + // We check the value to see what happened with the socket. if (err == 0) // Should not happen { return MEMCACHED_SUCCESS; @@ -198,7 +198,7 @@ static memcached_return_t set_hostinfo(memcached_instance_st* 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; @@ -294,7 +294,7 @@ static bool set_socket_options(memcached_instance_st* server) // If SOCK_CLOEXEC exists then we don't need to call the following if (SOCK_CLOEXEC == 0) { - if (FD_CLOEXEC) + if (FD_CLOEXEC != 0) { int flags; do @@ -447,12 +447,12 @@ static memcached_return_t unix_socket_connect(memcached_instance_st* server) do { int type= SOCK_STREAM; - if (SOCK_CLOEXEC) + if (SOCK_CLOEXEC != 0) { type|= SOCK_CLOEXEC; } - if (SOCK_NONBLOCK) + if (SOCK_NONBLOCK != 0) { type|= SOCK_NONBLOCK; } @@ -466,7 +466,10 @@ static memcached_return_t unix_socket_connect(memcached_instance_st* server) memset(&servAddr, 0, sizeof (struct sockaddr_un)); servAddr.sun_family= AF_UNIX; - strncpy(servAddr.sun_path, server->hostname(), sizeof(servAddr.sun_path)); /* Copy filename */ + if (strlen(server->hostname()) >= sizeof(servAddr.sun_path)) { + return memcached_set_error(*server, MEMCACHED_UNIX_SOCKET_PATH_TOO_BIG, MEMCACHED_AT); + } + strncpy(servAddr.sun_path, server->hostname(), sizeof(servAddr.sun_path)-1); /* Copy filename */ if (connect(server->fd, (struct sockaddr *)&servAddr, sizeof(servAddr)) == -1) { @@ -474,6 +477,7 @@ static memcached_return_t unix_socket_connect(memcached_instance_st* server) { case EINPROGRESS: case EALREADY: + case EAGAIN: server->events(POLLOUT); break; @@ -534,20 +538,13 @@ static memcached_return_t network_connect(memcached_instance_st* server) /* Create the socket */ while (server->address_info_next and server->fd == INVALID_SOCKET) { - /* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */ - if (memcached_is_udp(server->root) and server->address_info_next->ai_family != AF_INET) - { - server->address_info_next= server->address_info_next->ai_next; - continue; - } - int type= server->address_info_next->ai_socktype; - if (SOCK_CLOEXEC) + if (SOCK_CLOEXEC != 0) { type|= SOCK_CLOEXEC; } - if (SOCK_NONBLOCK) + if (SOCK_NONBLOCK != 0) { type|= SOCK_NONBLOCK; } @@ -713,6 +710,7 @@ static memcached_return_t backoff_handling(memcached_instance_st* server, bool& if (_gettime_success and server->next_retry < curr_time.tv_sec) { server->state= MEMCACHED_SERVER_STATE_NEW; + server->server_timeout_counter= 0; } else { @@ -760,7 +758,7 @@ static memcached_return_t _memcached_connect(memcached_instance_st* server, cons case MEMCACHED_CONNECTION_TCP: rc= network_connect(server); -#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT +#if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) if (LIBMEMCACHED_WITH_SASL_SUPPORT) { if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks)