From: Brian Aker Date: Sun, 7 Oct 2007 23:47:09 +0000 (-0700) Subject: Cleanup of behavior (refactored...) X-Git-Tag: 0.5~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=92f0cfa45cc559ee5c8445de737cd7a7b220502d;p=awesomized%2Flibmemcached Cleanup of behavior (refactored...) I am still using two enum... why? Trying to keep people fromm touching the main interface. I don't have to do this though.... --- diff --git a/include/memcached.h b/include/memcached.h index d687897a..da051070 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -74,6 +74,7 @@ typedef enum { MEMCACHED_BEHAVIOR_NO_BLOCK, MEMCACHED_BEHAVIOR_TCP_NODELAY, MEMCACHED_BEHAVIOR_MD5_HASHING, + MEMCACHED_BEHAVIOR_KETAMA, } memcached_behavior; typedef enum { diff --git a/lib/common.h b/lib/common.h index bc428c02..f922fee1 100644 --- a/lib/common.h +++ b/lib/common.h @@ -23,6 +23,7 @@ typedef enum { MEM_TCP_NODELAY= (1 << 1), MEM_REUSE_MEMORY= (1 << 2), MEM_USE_MD5= (1 << 3), + MEM_USE_KETAMA= (1 << 4), } memcached_flags; void md5_signature(unsigned char *key, unsigned int length, unsigned char *result); diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index bf90d75e..7383b4e2 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -13,33 +13,27 @@ memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, void *data) { + memcached_flags temp_flag; + switch (flag) { case MEMCACHED_BEHAVIOR_NO_BLOCK: - { - unsigned int *truefalse= (unsigned int *)data; - memcached_quit(ptr); - if (truefalse) - ptr->flags|= MEM_NO_BLOCK; - else - ptr->flags+= MEM_NO_BLOCK; - break; - } - + temp_flag= MEM_NO_BLOCK; case MEMCACHED_BEHAVIOR_TCP_NODELAY: + temp_flag= MEM_TCP_NODELAY; + case MEMCACHED_BEHAVIOR_MD5_HASHING: + temp_flag= MEM_USE_MD5; + case MEMCACHED_BEHAVIOR_KETAMA: + temp_flag= MEM_USE_KETAMA; { unsigned int *truefalse= (unsigned int *)data; memcached_quit(ptr); if (truefalse) - ptr->flags|= MEM_TCP_NODELAY; + ptr->flags|= temp_flag; else - ptr->flags+= MEM_TCP_NODELAY; + ptr->flags+= temp_flag; break; } - - case MEMCACHED_BEHAVIOR_MD5_HASHING: - ptr->flags+= MEM_USE_MD5; - break; } return MEMCACHED_SUCCESS; @@ -48,20 +42,19 @@ memcached_return memcached_behavior_set(memcached_st *ptr, unsigned long long memcached_behavior_get(memcached_st *ptr, memcached_behavior flag) { + memcached_flags temp_flag; + switch (flag) { case MEMCACHED_BEHAVIOR_NO_BLOCK: - if (ptr->flags & MEM_NO_BLOCK) - return 1; - else - return 0; + temp_flag= MEM_NO_BLOCK; case MEMCACHED_BEHAVIOR_TCP_NODELAY: - if (ptr->flags & MEM_TCP_NODELAY) - return 1; - else - return 0; + temp_flag= MEM_TCP_NODELAY; case MEMCACHED_BEHAVIOR_MD5_HASHING: - if (ptr->flags & MEM_USE_MD5) + temp_flag= MEM_USE_MD5; + case MEMCACHED_BEHAVIOR_KETAMA: + temp_flag= MEM_USE_KETAMA; + if (ptr->flags & temp_flag) return 1; else return 0; diff --git a/tests/test.c b/tests/test.c index 2c870d87..935e1400 100644 --- a/tests/test.c +++ b/tests/test.c @@ -466,6 +466,10 @@ void behavior_test(memcached_st *memc) value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY); assert(value == 1); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, &set); + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_MD5_HASHING); + assert(value == 1); + set= 0; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); @@ -475,6 +479,10 @@ void behavior_test(memcached_st *memc) memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY); assert(value == 0); + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, &set); + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_MD5_HASHING); + assert(value == 0); } void add_host_test1(memcached_st *memc)