From 52d5f8e32ae6e26932a07749ef5d5640e815a3f7 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 21 Nov 2007 22:54:48 -0800 Subject: [PATCH] memcached_behavior_set() can now modify the poll timeout --- ChangeLog | 3 + configure.ac | 2 +- docs/memcached_behavior.pod | 5 ++ include/memcached.h | 2 + lib/memcached.c | 2 + lib/memcached_behavior.c | 11 ++++ lib/memcached_io.c | 5 +- tests/function.c | 16 ++++++ tests/output.res | 107 ++++++++++++++++++++++++++++++++++++ 9 files changed, 151 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index efb225ca..9829ffdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +0.11 + * Added option to memcache_behavior_set() so that poll() can be timed out. + 0.10 Tue Nov 20 23:22:31 PST 2007 * Added append binary test. * Added MEMCACHED_BEHAVIOR_CACHE_LOOKUPS behavior so that you can save on diff --git a/configure.ac b/configure.ac index db73e65c..3c2310eb 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ MEMCACHED_LIBRARY_NAME=libmemcached #release versioning MEMCACHED_MAJOR_VERSION=0 -MEMCACHED_MINOR_VERSION=10 +MEMCACHED_MINOR_VERSION=11 MEMCACHED_MICRO_VERSION=0 #API version diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 20141907..cd3288da 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -59,6 +59,11 @@ Memcached can cache named lookups so that DNS lookups are made only once. Support CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty). +=item MEMCACHED_BEHAVIOR_POLL_TIMEOUT + +Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long. + + =back =head1 RETURN diff --git a/include/memcached.h b/include/memcached.h index e64bfb5d..54f52952 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -75,6 +75,7 @@ typedef enum { MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, MEMCACHED_BEHAVIOR_SUPPORT_CAS, + MEMCACHED_BEHAVIOR_POLL_TIMEOUT, } memcached_behavior; typedef enum { @@ -178,6 +179,7 @@ struct memcached_st { unsigned long long flags; int send_size; int recv_size; + int32_t poll_timeout; memcached_string_st result_buffer; memcached_hash hash; memcached_return warning; /* Future Use */ diff --git a/lib/memcached.c b/lib/memcached.c index 5f0d9820..a484462b 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -22,6 +22,7 @@ memcached_st *memcached_create(memcached_st *ptr) } string_ptr= memcached_string_create(ptr, &ptr->result_buffer, 0); WATCHPOINT_ASSERT(string_ptr); + ptr->poll_timeout= -1; return ptr; } @@ -73,6 +74,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) new_clone->number_of_hosts= ptr->number_of_hosts; new_clone->send_size= ptr->send_size; new_clone->recv_size= ptr->recv_size; + new_clone->poll_timeout= ptr->poll_timeout; return new_clone; } diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 76d0b61f..910fb392 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -44,6 +44,13 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: set_behavior_flag(ptr, MEM_USE_KETAMA, data); break; + case MEMCACHED_BEHAVIOR_POLL_TIMEOUT: + { + unsigned int timeout= (*((unsigned int *)data)); + + ptr->poll_timeout= timeout; + break; + } case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: { ptr->send_size= (*((int *)data)); @@ -87,6 +94,10 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: temp_flag= MEM_USE_KETAMA; break; + case MEMCACHED_BEHAVIOR_POLL_TIMEOUT: + { + return (unsigned long long)ptr->poll_timeout; + } case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE: { int sock_size; diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 06ac2e9b..973ccf95 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -11,7 +11,10 @@ static int io_wait(memcached_st *ptr, unsigned int server_key, unsigned read_or_ { struct pollfd fds[1]; short flags= 0; + struct timespec timer; + timer.tv_sec= 1; + timer.tv_nsec= 0; if (read_or_write) flags= POLLOUT | POLLERR; else @@ -21,7 +24,7 @@ static int io_wait(memcached_st *ptr, unsigned int server_key, unsigned read_or_ fds[0].fd= ptr->hosts[server_key].fd; fds[0].events= flags; - if (poll(fds, 1, -1) < 0) + if (poll(fds, 1, ptr->poll_timeout) < 0) return MEMCACHED_FAILURE; return MEMCACHED_SUCCESS; diff --git a/tests/function.c b/tests/function.c index 8316ad6c..640fbfe4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1676,6 +1676,21 @@ memcached_return pre_nodelay(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return poll_timeout(memcached_st *memc) +{ + int32_t timeout; + + timeout= 100; + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + + timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); + + assert(timeout == 100); + + return MEMCACHED_SUCCESS; +} + /* Clean the server before beginning testing */ test_st tests[] ={ @@ -1766,6 +1781,7 @@ collection_st collection[] ={ {"ketama", pre_hash_ketama, 0, tests}, {"unix_socket", pre_unix_socket, 0, tests}, {"unix_socket_nodelay", pre_nodelay, 0, tests}, + {"poll_timeout", poll_timeout, 0, tests}, {"gets", enable_cas, 0, tests}, // {"udp", pre_udp, 0, tests}, {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3}, diff --git a/tests/output.res b/tests/output.res index 9bd97459..6594f947 100644 --- a/tests/output.res +++ b/tests/output.res @@ -1285,3 +1285,110 @@ Found key bytes_read Found key bytes_written Found key limit_maxbytes Found key threads +Error 0 -> SUCCESS +Error 1 -> FAILURE +Error 2 -> HOSTNAME LOOKUP FAILURE +Error 3 -> CONNECTION FAILURE +Error 4 -> CONNECTION BIND FAILURE +Error 5 -> WRITE FAILURE +Error 6 -> READ FAILURE +Error 7 -> UNKNOWN READ FAILURE +Error 8 -> PROTOCOL ERROR +Error 9 -> CLIENT ERROR +Error 10 -> SERVER ERROR +Error 11 -> CONNECTION SOCKET CREATE FAILURE +Error 12 -> CONNECTION DATA EXISTS +Error 13 -> CONNECTION DATA DOES NOT EXIST +Error 14 -> NOT STORED +Error 15 -> STORED +Error 16 -> NOT FOUND +Error 17 -> MEMORY ALLOCATION FAILURE +Error 18 -> PARTIAL READ +Error 19 -> SOME ERRORS WERE REPORTED +Error 20 -> NO SERVERS DEFINED +Error 21 -> SERVER END +Error 22 -> SERVER DELETE +Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE +Error 25 -> SYSTEM ERROR +Error 26 -> COULD NOT OPEN UNIX SOCKET +Error 27 -> ACTION NOT SUPPORTED +Error 28 -> A KEY LENGTH OF ZERO WAS PROVIDED +Found key pid +Found key uptime +Found key time +Found key version +Found key pointer_size +Found key rusage_user +Found key rusage_system +Found key rusage_user_seconds +Found key rusage_user_microseconds +Found key rusage_system_seconds +Found key rusage_system_microseconds +Found key curr_items +Found key total_items +Found key bytes +Found key curr_connections +Found key total_connections +Found key connection_structures +Found key cmd_get +Found key cmd_set +Found key get_hits +Found key get_misses +Found key evictions +Found key bytes_read +Found key bytes_written +Found key limit_maxbytes +Found key threads +Found key pid +Found key uptime +Found key time +Found key version +Found key pointer_size +Found key rusage_user +Found key rusage_system +Found key rusage_user_seconds +Found key rusage_user_microseconds +Found key rusage_system_seconds +Found key rusage_system_microseconds +Found key curr_items +Found key total_items +Found key bytes +Found key curr_connections +Found key total_connections +Found key connection_structures +Found key cmd_get +Found key cmd_set +Found key get_hits +Found key get_misses +Found key evictions +Found key bytes_read +Found key bytes_written +Found key limit_maxbytes +Found key threads +Found key pid +Found key uptime +Found key time +Found key version +Found key pointer_size +Found key rusage_user +Found key rusage_system +Found key rusage_user_seconds +Found key rusage_user_microseconds +Found key rusage_system_seconds +Found key rusage_system_microseconds +Found key curr_items +Found key total_items +Found key bytes +Found key curr_connections +Found key total_connections +Found key connection_structures +Found key cmd_get +Found key cmd_set +Found key get_hits +Found key get_misses +Found key evictions +Found key bytes_read +Found key bytes_written +Found key limit_maxbytes +Found key threads -- 2.30.2