From: Brian Aker Date: Wed, 27 Feb 2008 14:39:14 +0000 (-0800) Subject: Possible patch (and fix) X-Git-Tag: 0.20~1^2~55^2~3^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fe01674c1b5b0b06b9edab9cff4f6f59115668f6;p=awesomized%2Flibmemcached Possible patch (and fix) --- diff --git a/THANKS b/THANKS index 45809cec..35db5339 100644 --- a/THANKS +++ b/THANKS @@ -8,3 +8,4 @@ Tim Bunce - Perl Driver work and feedback on API Kevin Dalley - Bug Fixes Patrick Galbraith - work on C++ interface Ross McFarland - Idea for sorting servers. +Marcelo Fernandez - TCP/IP timeout pieces diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index 9d935e02..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) { @@ -136,47 +137,6 @@ test_connect: { switch (errno) { case EINPROGRESS: - { - struct timeval tm = { ptr->root->connect_timeout, 0 }; - socklen_t len= sizeof(int); - fd_set wset; - int error=0, value; - - FD_ZERO(&wset); - FD_SET(ptr->fd, &wset); - - select(ptr->fd+1, NULL, &wset, NULL, &tm); - if (FD_ISSET(ptr->fd, &wset) != 0) - { - if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &value, &len) == 0) - { - if (value) - { - error= 1; - } - } - else - { - error= 1; - } - } - else - { - error= 1; - } - - if (error) - { - 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 EALREADY: case EINTR: goto test_connect; @@ -237,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 */