From: Brian Aker Date: Fri, 11 Jan 2008 21:43:36 +0000 (-0800) Subject: MEMCACHED_BEHAVIOR_USER_DATA work. This allows a client application to store X-Git-Tag: 0.13~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b1daf61bf1665041f30fff7c96d61de4658f8db3;p=m6w6%2Flibmemcached MEMCACHED_BEHAVIOR_USER_DATA work. This allows a client application to store a pointer set of data into the library. --- diff --git a/ChangeLog b/ChangeLog index ed7a8148..46f277c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 0.13 + * MEMCACHED_BEHAVIOR_USER_DATA added to store user pointer. * Fix for failure to connect to invalidate socket. * Patch from Marc Rossi to add --hash option for memcp, memrm, and memcat. * Kevin's patch for fixing EOF issues during a read. diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index b76ae054..bd8c85a7 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -73,7 +73,13 @@ Support CAS operations (this is not enabled by default at this point in the serv 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. -=item MEMCACHED_BUFFERED +=item MEMCACHED_BEHAVIOR_USER_DATA + +This allows you to store a pointer to a specifc piece of data. This can be +retrieved from inside of memcached_fetch_exectue(). Cloning a memcached_st +will copy the pointer to the clone. + +=item MEMCACHED_BEHAVIOR_BUFFER_REQUESTS Enabling buffered IO causes commands to "buffer" instead of being sent. Any action that gets data causes this buffer to be be sent to the remote diff --git a/include/memcached.h b/include/memcached.h index fb836284..d73a16be 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -90,6 +90,7 @@ typedef enum { MEMCACHED_BEHAVIOR_POLL_TIMEOUT, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, + MEMCACHED_BEHAVIOR_USER_DATA, } memcached_behavior; typedef enum { @@ -199,6 +200,7 @@ struct memcached_st { memcached_result_st result; memcached_hash hash; memcached_server_distribution distribution; + void *user_data; unsigned int wheel[MEMCACHED_WHEEL_SIZE]; #ifdef NOT_USED /* Future Use */ uint8_t replicas; diff --git a/lib/memcached.c b/lib/memcached.c index 24c3b8bc..25a287ad 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -82,6 +82,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) new_clone->poll_timeout= ptr->poll_timeout; new_clone->distribution= ptr->distribution; new_clone->hash= ptr->hash; + new_clone->user_data= ptr->user_data; return new_clone; } diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index 31d8f052..55b9da67 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -49,6 +49,9 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: set_behavior_flag(ptr, MEM_USE_KETAMA, data); break; + case MEMCACHED_BEHAVIOR_USER_DATA: + ptr->user_data= data; + break; case MEMCACHED_BEHAVIOR_POLL_TIMEOUT: { int32_t timeout= (*((int32_t *)data)); @@ -104,6 +107,8 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_KETAMA: temp_flag= MEM_USE_KETAMA; break; + case MEMCACHED_BEHAVIOR_USER_DATA: + return (unsigned long long)ptr->user_data; case MEMCACHED_BEHAVIOR_POLL_TIMEOUT: { return (unsigned long long)ptr->poll_timeout;