From 6da3006b68068d3f4928400ab652f8564cb7dca3 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Sun, 14 Jun 2009 16:36:57 +0200 Subject: [PATCH] Add memcached_[gs]et_user_data and updated the doc for memcached_set_memory_allocators to point to the functions --- .bzrignore | 2 ++ docs/Makefile.am | 14 ++++++-- docs/libmemcached.pod | 2 +- docs/memcached_memory_allocators.pod | 7 +++- docs/memcached_user_data.pod | 49 ++++++++++++++++++++++++++++ libmemcached/memcached.c | 11 +++++++ libmemcached/memcached.h | 3 ++ tests/function.c | 11 +++++++ 8 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 docs/memcached_user_data.pod diff --git a/.bzrignore b/.bzrignore index 67b1698c..4b8966e1 100644 --- a/.bzrignore +++ b/.bzrignore @@ -97,6 +97,8 @@ docs/memslap.1 docs/memstat.1 docs/memcached_set_memory_allocators.3 docs/memcached_get_memory_allocators.3 +docs/memcached_set_user_data.3 +docs/memcached_get_user_data.3 libmemcached/.deps libmemcached/.libs libmemcached/Makefile diff --git a/docs/Makefile.am b/docs/Makefile.am index e7c7df35..fa2d3383 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -32,7 +32,8 @@ EXTRA_DIST = libmemcached.pod\ memcached_flush_buffers.pod\ memcached_analyze.pod\ memcached_generate_hash_value.pod\ - memcached_memory_allocators.pod + memcached_memory_allocators.pod\ + memory_user_data.pod man_MANS = libmemcached.3\ libmemcached_examples.3\ @@ -98,7 +99,9 @@ man_MANS = libmemcached.3\ memcached_dump.3\ memcached_generate_hash_value.3\ memcached_set_memory_allocators.3\ - memcached_get_memory_allocators.3 + memcached_get_memory_allocators.3\ + memcached_set_user_data.3\ + memcached_get_user_data.3 if BUILD_LIBMEMCACHEDUTIL man_MANS+= libmemcachedutil.3 \ @@ -316,6 +319,12 @@ memcached_get_memory_allocators.3: memcached_memory_allocators.pod memcached_set_memory_allocators.3: memcached_memory_allocators.pod @POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_memory_allocators.pod > memcached_set_memory_allocators.3 +memcached_get_user_data.3: memcached_user_data.pod + @POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_user_data.pod > memcached_get_user_data.3 + +memcached_set_user_data.3: memcached_user_data.pod + @POD2MAN@ -c "libmemcached" -r "" -s 3 ${top_srcdir}/docs/memcached_user_data.pod > memcached_set_user_data.3 + memcached_pool_create.3: memcached_pool.pod @POD2MAN@ -c "libmemcachedutil" -r "" -s 3 ${top_srcdir}/docs/memcached_pool.pod > memcached_pool_create.3 @@ -380,6 +389,7 @@ test: podchecker $(top_srcdir)/docs/memcached_flush_buffers.pod podchecker $(top_srcdir)/docs/memcached_pool.pod podchecker $(top_srcdir)/docs/memcached_memory_allocators.pod + podchecker $(top_srcdir)/docs/memcached_user_data.pod html-local: pod2htmltree "/libmemcached" . diff --git a/docs/libmemcached.pod b/docs/libmemcached.pod index 19472e83..e1a95a73 100644 --- a/docs/libmemcached.pod +++ b/docs/libmemcached.pod @@ -121,7 +121,7 @@ Brian Aker, Ebrian@tangent.orgE =head1 SEE ALSO -memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcached_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3) memcached_version(3) memcached_lib_version(3) memcached_result_set_value(3) memcached_dump(3) memdump(1) memcached_set_memory_allocators(3) memcached_get_memory_allocators(3) +memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcached_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3) memcached_version(3) memcached_lib_version(3) memcached_result_set_value(3) memcached_dump(3) memdump(1) memcached_set_memory_allocators(3) memcached_get_memory_allocators(3) memcached_get_user_data(3) memcached_set_user_data(3) =cut diff --git a/docs/memcached_memory_allocators.pod b/docs/memcached_memory_allocators.pod index b2ac84cb..5d6d00ae 100644 --- a/docs/memcached_memory_allocators.pod +++ b/docs/memcached_memory_allocators.pod @@ -46,6 +46,11 @@ all functions to reset them to the default values. memcached_get_memory_allocators() is used to get the currently used memory allocators by a mamcached handle. +The first argument to the memory allocator functions is a pointer to a +memcached structure, and you may use the memcached_set_user_data() and +memcached_get_user_data() to store a user-specific value to each memcached +structure. + =head1 RETURN memcached_set_memory_allocators() return MEMCACHED_SUCCESS upon success, @@ -62,7 +67,7 @@ Trond Norbye, Etrond.norbye@sun.comE =head1 SEE ALSO -memcached(1) libmemcached(3) +memcached(1) libmemcached(3) memcached_get_user_data(3) memcached_set_user_data(3) =cut diff --git a/docs/memcached_user_data.pod b/docs/memcached_user_data.pod new file mode 100644 index 00000000..d5161a1d --- /dev/null +++ b/docs/memcached_user_data.pod @@ -0,0 +1,49 @@ +=head1 NAME + +memcached_set_user_data, memcached_get_user_data + +=head1 LIBRARY + +C Client Library for memcached (libmemcached, -lmemcached) + +=head1 SYNOPSIS + + #include + + void *memcached_get_user_data(memcached_st *ptr); + void *memcached_set_user_data(memcached_st *ptr, void *data); + +=head1 DESCRIPTION + +libmemcached(3) allows you to store a pointer to a user specific data inside +the memcached_st structure. + +memcached_set_user_data() is used to set the user specific data in the +memcached_st structure. + +memcached_get_user_data() is used to retrieve the user specific data in +the memcached_st structure. + +=head1 RETURN + +memcached_set_user_data() returns the previous value of the user specific +data. + +memcached_get_user_data() returns the current value uf the user specific +data. + +=head1 HOME + +To find out more information please check: +L + +=head1 AUTHOR + +Trond Norbye, Etrond.norbye@sun.comE + +=head1 SEE ALSO + +memcached(1) libmemcached(3) + +=cut + diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 61a3b399..5991aabb 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -136,3 +136,14 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) return new_clone; } +void *memcached_get_user_data(memcached_st *ptr) +{ + return ptr->user_data; +} + +void *memcached_set_user_data(memcached_st *ptr, void *data) +{ + void *ret= ptr->user_data; + ptr->user_data= data; + return ret; +} diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index a0e2f6de..607fb4b6 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -243,6 +243,9 @@ void memcached_get_memory_allocators(memcached_st *ptr, memcached_realloc_function *mem_realloc, memcached_calloc_function *mem_calloc); +void *memcached_get_user_data(memcached_st *ptr); +void *memcached_set_user_data(memcached_st *ptr, void *data); + #ifdef __cplusplus } #endif diff --git a/tests/function.c b/tests/function.c index 4b7fbdee..99ad776a 100644 --- a/tests/function.c +++ b/tests/function.c @@ -263,6 +263,16 @@ static test_return clone_test(memcached_st *memc) return 0; } +static test_return userdata_test(memcached_st *memc) +{ + void* foo; + assert(memcached_set_user_data(memc, foo) == NULL); + assert(memcached_get_user_data(memc) == foo); + assert(memcached_set_user_data(memc, NULL) == foo); + + return TEST_SUCCESS; +} + static test_return connection_test(memcached_st *memc) { memcached_return rc; @@ -4131,6 +4141,7 @@ test_st tests[] ={ {"connection_test", 0, connection_test}, {"callback_test", 0, callback_test}, {"behavior_test", 0, behavior_test}, + {"userdata_test", 0, userdata_test}, {"error", 0, error_test }, {"set", 0, set_test }, {"set2", 0, set_test2 }, -- 2.30.2