X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_connect.c;h=1b4a5fd5839a22373549f29d68c15634eb68b90b;hb=51aa1233e4981967f06dd3432cd3a6ed83a35607;hp=b4642c7630fb542ece0935e0f9312ebf31b7ab60;hpb=fddf7c8e17eb5b970828ab1dec54dbbac159693d;p=awesomized%2Flibmemcached diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index b4642c76..1b4a5fd5 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -1,4 +1,5 @@ #include "common.h" +#include static memcached_return set_hostinfo(memcached_server_st *server) { @@ -101,7 +102,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr) int flags; flags= fcntl(ptr->fd, F_GETFL, 0); - if (flags != -1) + unlikely (flags != -1) { (void)fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK); } @@ -135,9 +136,8 @@ test_connect: sizeof(servAddr)) < 0) { switch (errno) { - /* We are spinning waiting on connect */ - case EALREADY: case EINPROGRESS: + case EALREADY: case EINTR: goto test_connect; case EISCONN: /* We were spinning waiting on connect */ @@ -197,6 +197,27 @@ test_connect: /* We are spinning waiting on connect */ case EALREADY: case EINPROGRESS: + { + struct pollfd fds[1]; + int error; + + memset(&fds, 0, sizeof(struct pollfd)); + fds[0].fd= ptr->fd; + fds[0].events= POLLOUT | POLLERR; + error= poll(fds, 1, ptr->root->connect_timeout); + + if (error != 1) + { + ptr->cached_errno= errno; + WATCHPOINT_ERRNO(ptr->cached_errno); + close(ptr->fd); + ptr->fd= -1; + return MEMCACHED_ERRNO; + } + + break; + } + /* We are spinning waiting on connect */ case EINTR: goto test_connect; case EISCONN: /* We were spinning waiting on connect */