From: Date: Wed, 30 Jul 2008 22:19:22 +0000 (-0700) Subject: Added MEMCACHED_BEHAVIOR_SND_TIMEOUT, MEMCACHED_BEHAVIOR_RCV_TIMEOUT X-Git-Tag: _23~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6f42f1c77da54da0b19274cc0d6b6c9745e40de0;p=m6w6%2Flibmemcached Added MEMCACHED_BEHAVIOR_SND_TIMEOUT, MEMCACHED_BEHAVIOR_RCV_TIMEOUT --- diff --git a/ChangeLog b/ChangeLog index f047278e..c422b82c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ * Support for weighted Ketama from Yin Chen. * Fix for Chinese * Fix for 0 length key to trigger bad key. + * Added behaviors MEMCACHED_BEHAVIOR_SND_TIMEOUT, MEMCACHED_BEHAVIOR_RCV_TIMEOUT 0.22 Mon Jul 14 09:24:11 PDT 2008 * Fix where master key was no being checked for "bad key" diff --git a/configure.ac b/configure.ac index d0c871c8..a99c994b 100644 --- a/configure.ac +++ b/configure.ac @@ -53,7 +53,7 @@ sinclude(config/debug.m4) sinclude(config/dtrace.m4) sinclude(config/byteorder.m4) sinclude(config/64bit.m4) -sinclude(config/protocol_binary.m4) +#sinclude(config/protocol_binary.m4) # We only support GCC and Sun's forte at the moment if test "$GCC" = "yes" diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 8821dcdf..7807bc9f 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -44,6 +44,18 @@ available for storage functions. For read operations it is currently similar in performance to the non-blocking method (this is being looked into). +=item MEMCACHED_BEHAVIOR_SND_TIMEOUT + +This sets the microsecond behavior of the socket against the SO_SNDTIMEO flag. +In cases where you cannot use non-blocking IO this will allow you to still have +timeouts on the sending of data. + +=item MEMCACHED_BEHAVIOR_RCV_TIMEOUT + +This sets the microsecond behavior of the socket against the SO_RCVTIMEO flag. +In cases where you cannot use non-blocking IO this will allow you to still have +timeouts on the reading of data. + =item MEMCACHED_BEHAVIOR_TCP_NODELAY Turns on the no-delay feature for connecting sockets (may be faster in some diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index dcf1a4a0..40f8e263 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -106,6 +106,9 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) new_clone->hash_continuum= ptr->hash_continuum; new_clone->user_data= ptr->user_data; + new_clone->snd_timeout= ptr->snd_timeout; + new_clone->rcv_timeout= ptr->rcv_timeout; + new_clone->on_clone= ptr->on_clone; new_clone->on_cleanup= ptr->on_cleanup; new_clone->call_free= ptr->call_free; diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 911b0444..0cbb12f1 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -95,6 +95,8 @@ struct memcached_st { size_t prefix_key_length; memcached_hash hash_continuum; uint32_t continuum_points_counter; + int32_t snd_timeout; + int32_t rcv_timeout; }; diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index 6b36626e..f61fba52 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -23,6 +23,12 @@ memcached_return memcached_behavior_set(memcached_st *ptr, { switch (flag) { + case MEMCACHED_BEHAVIOR_SND_TIMEOUT: + ptr->snd_timeout= (int32_t)data; + break; + case MEMCACHED_BEHAVIOR_RCV_TIMEOUT: + ptr->rcv_timeout= (int32_t)data; + break; case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL: set_behavior_flag(ptr, MEM_BINARY_PROTOCOL, data); break; diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index a4ed6680..33a8a521 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -45,17 +45,26 @@ static memcached_return set_socket_options(memcached_server_st *ptr) if (ptr->type == MEMCACHED_CONNECTION_UDP) return MEMCACHED_SUCCESS; - if (ptr->root->flags & MEM_NO_BLOCK) + if (ptr->root->snd_timeout) { int error; struct timeval waittime; - waittime.tv_sec= 10; - waittime.tv_usec= 0; + waittime.tv_sec= 0; + waittime.tv_usec= ptr->root->snd_timeout; error= setsockopt(ptr->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); WATCHPOINT_ASSERT(error == 0); + } + + if (ptr->root->rcv_timeout) + { + int error; + struct timeval waittime; + + waittime.tv_sec= 0; + waittime.tv_usec= ptr->root->rcv_timeout; error= setsockopt(ptr->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); diff --git a/libmemcached/memcached_constants.h b/libmemcached/memcached_constants.h index 0ee2568f..d7770a73 100644 --- a/libmemcached/memcached_constants.h +++ b/libmemcached/memcached_constants.h @@ -89,6 +89,8 @@ typedef enum { MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + MEMCACHED_BEHAVIOR_SND_TIMEOUT, + MEMCACHED_BEHAVIOR_RCV_TIMEOUT, } memcached_behavior; typedef enum { diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index dcaa8988..a84ef4f2 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -250,6 +250,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr, unsigned int number_of_keys) { memcached_return rc= MEMCACHED_NOTFOUND; + int x; int flush= number_of_keys == 1; @@ -257,7 +258,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr, If a server fails we warn about errors and start all over with sending keys to the server. */ - for (int x= 0; x < number_of_keys; x++) + for (x= 0; x < number_of_keys; x++) { unsigned int server_key; @@ -306,7 +307,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr, request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; - for (int x= 0; x < ptr->number_of_hosts; x++) + for (x= 0; x < ptr->number_of_hosts; x++) if (memcached_server_response_count(&ptr->hosts[x])) { if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1) diff --git a/tests/function.c b/tests/function.c index e37aabef..1cfd96a4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2813,6 +2813,14 @@ memcached_return pre_nodelay(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return pre_settimer(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 1000); + + return MEMCACHED_SUCCESS; +} + memcached_return poll_timeout(memcached_st *memc) { int32_t timeout; @@ -2959,9 +2967,10 @@ test_st consistent_weighted_tests[] ={ collection_st collection[] ={ {"block", 0, 0, tests}, - {"binary", pre_binary, 0, tests}, +// {"binary", pre_binary, 0, tests}, {"nonblock", pre_nonblock, 0, tests}, {"nodelay", pre_nodelay, 0, tests}, + {"settimer", pre_settimer, 0, tests}, {"md5", pre_md5, 0, tests}, {"crc", pre_crc, 0, tests}, {"hsieh", pre_hsieh, 0, tests},