From: Date: Thu, 6 Mar 2008 04:22:39 +0000 (-0500) Subject: MEMCACHED_BEHAVIOR_RETRY_TIMEOUT added for timeout X-Git-Tag: _20~1^2~68 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5ed23cb1d7aaa03f05b58dfeabeee72f5aff91c5;p=m6w6%2Flibmemcached MEMCACHED_BEHAVIOR_RETRY_TIMEOUT added for timeout --- diff --git a/ChangeLog b/ChangeLog index a4579804..ff863160 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ non-block mode. * Fix plus tests for non-zero value objects and flags. * MEMCACHED_HASH_MURMUR added for murmur algorithm provided. + * MEMCACHED_BEHAVIOR_RETRY_TIMEOUT added to keep connecting from looping + on timeout. 0.16 Mon Feb 18 00:30:25 PST 2008 * Work on the UDP protocol diff --git a/include/memcached.h b/include/memcached.h index 7fd94e7d..afd43b41 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -105,6 +105,7 @@ typedef enum { MEMCACHED_BEHAVIOR_SORT_HOSTS, MEMCACHED_BEHAVIOR_VERIFY_KEY, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, + MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, } memcached_behavior; typedef enum { @@ -161,6 +162,7 @@ struct memcached_server_st { uint8_t minor_version; uint8_t micro_version; uint16_t count; + time_t next_retry; memcached_st *root; }; @@ -222,6 +224,7 @@ struct memcached_st { int recv_size; int32_t poll_timeout; int32_t connect_timeout; + int32_t retry_timeout; memcached_result_st result; memcached_hash hash; memcached_server_distribution distribution; diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 15ee08c9..ce598fc0 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -80,6 +80,11 @@ memcached_return memcached_behavior_set(memcached_st *ptr, ptr->connect_timeout= timeout; break; } + case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT: + { + ptr->retry_timeout= (int32_t)data; + break; + } case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: { ptr->send_size= (*((int *)data)); @@ -144,6 +149,10 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, { return (unsigned long long)ptr->connect_timeout; } + case MEMCACHED_BEHAVIOR_RETRY_TIMEOUT: + { + return (unsigned long long)ptr->retry_timeout; + } case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: { int sock_size; diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index 50c6fa62..4bfc710f 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -246,6 +246,13 @@ test_connect: WATCHPOINT_ERRNO(ptr->cached_errno); close(ptr->fd); ptr->fd= -1; + if (ptr->root->retry_timeout) + { + struct timeval next_time; + + gettimeofday(&next_time, NULL); + ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout; + } } } else @@ -269,6 +276,14 @@ memcached_return memcached_connect(memcached_server_st *ptr) memcached_return rc= MEMCACHED_NO_SERVERS; LIBMEMCACHED_MEMCACHED_CONNECT_START(); + if (ptr->root->retry_timeout) + { + struct timeval next_time; + + gettimeofday(&next_time, NULL); + if (next_time.tv_sec < ptr->next_retry) + return MEMCACHED_TIMEOUT; + } /* We need to clean up the multi startup piece */ switch (ptr->type) { diff --git a/lib/memcached_hosts.c b/lib/memcached_hosts.c index de006dd6..fb53fa22 100644 --- a/lib/memcached_hosts.c +++ b/lib/memcached_hosts.c @@ -61,6 +61,8 @@ static void host_reset(memcached_st *ptr, memcached_server_st *host, host->fd= -1; host->type= type; host->read_ptr= host->read_buffer; + if (ptr) + host->next_retry= ptr->retry_timeout; host->sockaddr_inited= MEMCACHED_NOT_ALLOCATED; }