X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcached%2Fconnect.cc;h=84617133741a9e5332e212ac50f29af4f2a8b563;hb=ac25aff8b62e8596e20f0fd2a2c3eda96bdb437e;hp=248cd7cd387955987b141e3caf291fcbb00cc5f7;hpb=ad30cb9bc8b8a0a0a371eb3ba7f154891820584f;p=awesomized%2Flibmemcached diff --git a/src/libmemcached/connect.cc b/src/libmemcached/connect.cc index 248cd7cd..84617133 100644 --- a/src/libmemcached/connect.cc +++ b/src/libmemcached/connect.cc @@ -14,32 +14,10 @@ */ #include "libmemcached/common.h" +#include "p9y/poll.hpp" #include -#ifndef SOCK_CLOEXEC -# define SOCK_CLOEXEC 0 -#endif - -#ifndef SOCK_NONBLOCK -# define SOCK_NONBLOCK 0 -#endif - -#ifndef FD_CLOEXEC -# define FD_CLOEXEC 0 -#endif - -#ifndef SO_NOSIGPIPE -# define SO_NOSIGPIPE 0 -#endif - -#ifndef TCP_NODELAY -# define TCP_NODELAY 0 -#endif - -#ifndef TCP_KEEPIDLE -# define TCP_KEEPIDLE 0 -#endif static memcached_return_t connect_poll(memcached_instance_st *server, const int connection_error) { struct pollfd fds[1]; @@ -59,10 +37,10 @@ static memcached_return_t connect_poll(memcached_instance_st *server, const int while (--loop_max) // Should only loop on cases of ERESTART or EINTR { int number_of; - if ((number_of = poll(fds, 1, server->root->connect_timeout)) == -1) { + if ((number_of = poll(fds, 1, server->root->connect_timeout)) == SOCKET_ERROR) { int local_errno = get_socket_errno(); // We cache in case closesocket() modifies errno switch (local_errno) { -#ifdef __linux__ +#ifdef HAVE_ERESTART case ERESTART: #endif case EINTR: @@ -90,7 +68,7 @@ static memcached_return_t connect_poll(memcached_instance_st *server, const int } if (number_of == 0) { - if (connection_error == EINPROGRESS) { + if (connection_error != EALREADY) { int err; socklen_t len = sizeof(err); if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == -1) { @@ -138,7 +116,7 @@ static memcached_return_t connect_poll(memcached_instance_st *server, const int } assert(fds[0].revents & POLLOUT); - if (fds[0].revents & POLLOUT and connection_error == EINPROGRESS) { + if (fds[0].revents & POLLOUT and connection_error != EALREADY) { int err; socklen_t len = sizeof(err); if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == -1) { @@ -521,6 +499,7 @@ static memcached_return_t network_connect(memcached_instance_st *server) { #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif + case EAGAIN: case EINPROGRESS: // nonblocking mode - first return case EALREADY: // nonblocking mode - subsequent returns {