From e46e60cc9ede45420b9bebfae61114ad45b39d91 Mon Sep 17 00:00:00 2001 From: Andre Cruz Date: Mon, 8 Mar 2010 15:39:15 +0000 Subject: [PATCH] Implemented the TCP_KEEPIDLE tcp option. This is only available on Linux. --- docs/memcached_behavior.pod | 4 ++++ libmemcached/connect.c | 14 ++++++++++++++ libmemcached/memcached.c | 3 +++ libmemcached/memcached.h | 1 + 4 files changed, 22 insertions(+) diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 4095e8a5..c9a7104f 100644 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -231,6 +231,10 @@ MEMCACHED_BEHAVIOR_TCP_NODELAY when set. Enable TCP_KEEPALIVE behavior. +=item MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE + +Specify time, in seconds, to mark a connection as idle. This is only available as an option Linux. + =item MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE Find the current size of SO_SNDBUF. A value of 0 means either an error diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 41bd7fb0..67ceacab 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -85,6 +85,20 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) } #endif +#ifdef TCP_KEEPIDLE + if (ptr->root->tcp_keepidle) + { + int flag= 1; + int error; + + error= setsockopt(ptr->fd, IPPROTO_TCP, TCP_KEEPIDLE, + &flag, (socklen_t)sizeof(int)); + WATCHPOINT_ASSERT(error == 0); + if (error) + return MEMCACHED_FAILURE; + } +#endif + if (ptr->root->flags.no_block) { int error; diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 647d0f79..aef49973 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -63,6 +63,8 @@ static inline bool _memcached_init(memcached_st *self) self->io_msg_watermark= 500; self->io_bytes_watermark= 65 * 1024; + self->tcp_keepidle= 0; + self->io_key_prefetch= 0; self->cached_errno= 0; self->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; @@ -226,6 +228,7 @@ memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source) new_clone->io_bytes_watermark= source->io_bytes_watermark; new_clone->io_key_prefetch= source->io_key_prefetch; new_clone->number_of_replicas= source->number_of_replicas; + new_clone->tcp_keepidle= source->tcp_keepidle; if (memcached_server_count(source)) rc= memcached_push(new_clone, source); diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index db164649..1392cb2b 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -94,6 +94,7 @@ struct memcached_st { uint32_t io_msg_watermark; uint32_t io_bytes_watermark; uint32_t io_key_prefetch; + uint32_t tcp_keepidle; int cached_errno; int32_t poll_timeout; int32_t connect_timeout; -- 2.30.2