From: Date: Wed, 20 Feb 2008 08:41:34 +0000 (+0530) Subject: First view of server cursor function. X-Git-Tag: _20~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ea2b5072372d2ff568932b99453123df0e85a840;p=m6w6%2Flibmemcached First view of server cursor function. --- diff --git a/docs/memcached_get.pod b/docs/memcached_get.pod index bd8623bb..5557e7c3 100755 --- a/docs/memcached_get.pod +++ b/docs/memcached_get.pod @@ -46,7 +46,7 @@ C Client Library for memcached (libmemcached, -lmemcached) memcached_return *error); memcached_return memcached_fetch_execute(memcached_st *ptr, - unsigned int (*callback[])(memcached_st *ptr, memcached_result_st *result, void *context), + memcached_return (*callback[])(memcached_st *ptr, memcached_result_st *result, void *context), void *context, unsigned int number_of_callbacks); diff --git a/include/memcached.h b/include/memcached.h index b3c26b1a..419f1949 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -81,7 +81,8 @@ typedef memcached_return (*memcached_cleanup_func)(memcached_st *ptr); typedef void (*memcached_free_function)(memcached_st *ptr, void *mem); typedef void *(*memcached_malloc_function)(memcached_st *ptr, const size_t size); typedef void *(*memcached_realloc_function)(memcached_st *ptr, void *mem, const size_t size); -typedef unsigned int (*memcached_execute_function)(memcached_st *ptr, memcached_result_st *result, void *context); +typedef memcached_return (*memcached_execute_function)(memcached_st *ptr, memcached_result_st *result, void *context); +typedef memcached_return (*memcached_server_function)(memcached_st *ptr, memcached_server_st *server, void *context); typedef enum { MEMCACHED_DISTRIBUTION_MODULA, @@ -410,6 +411,11 @@ void *memcached_callback_get(memcached_st *ptr, memcached_callback flag, memcached_return *error); +memcached_return memcached_server_cursor(memcached_st *ptr, + memcached_server_function *callback, + void *context, + unsigned int number_of_callbacks); + /* Result Struct */ void memcached_result_free(memcached_result_st *result); memcached_result_st *memcached_result_create(memcached_st *ptr, diff --git a/lib/Makefile.am b/lib/Makefile.am index 0783bcf4..5257b7ba 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -48,6 +48,7 @@ libmemcached_la_SOURCES = crc.c \ memcached_parse.c \ memcached_response.c \ memcached_result.c \ + memcached_server.c \ memcached_storage.c \ memcached_string.c \ memcached_stats.c \ diff --git a/lib/memcached_fetch_execute.c b/lib/memcached_fetch_execute.c index 253687ee..29d76244 100644 --- a/lib/memcached_fetch_execute.c +++ b/lib/memcached_fetch_execute.c @@ -34,11 +34,11 @@ memcached_return memcached_fetch_execute(memcached_st *ptr, for (x= 0; x < number_of_callbacks; x++) { - unsigned int iferror; + memcached_return iferror; iferror= (*callback[x])(ptr, result, context); - if (iferror) + if (iferror != MEMCACHED_SUCCESS) continue; } } diff --git a/lib/memcached_server.c b/lib/memcached_server.c new file mode 100644 index 00000000..fd86e6d6 --- /dev/null +++ b/lib/memcached_server.c @@ -0,0 +1,26 @@ +#include "common.h" + +memcached_return memcached_server_cursor(memcached_st *ptr, + memcached_server_function *callback, + void *context, + unsigned int number_of_callbacks) +{ + unsigned int y; + + for (y= 0; y < ptr->number_of_hosts; y++) + { + unsigned int x; + + for (x= 0; x < number_of_callbacks; x++) + { + unsigned int iferror; + + iferror= (*callback[x])(ptr, &ptr->hosts[y], context); + + if (iferror) + continue; + } + } + + return MEMCACHED_SUCCESS; +} diff --git a/tests/function.c b/tests/function.c index d79e956c..1312c36d 100644 --- a/tests/function.c +++ b/tests/function.c @@ -474,6 +474,24 @@ uint8_t flush_test(memcached_st *memc) return 0; } +memcached_return server_function(memcached_st *ptr, memcached_server_st *server, void *context) +{ + /* Do Nothing */ + + return MEMCACHED_SUCCESS; +} + +uint8_t memcached_server_cursor_test(memcached_st *memc) +{ + char *context= "foo bad"; + memcached_server_function callbacks[1]; + + callbacks[0]= server_function; + memcached_server_cursor(memc, callbacks, context, 1); + + return 0; +} + uint8_t bad_key_test(memcached_st *memc) { memcached_return rc; @@ -569,7 +587,6 @@ uint8_t set_test2(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); - WATCHPOINT_ERROR(rc); assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } @@ -884,7 +901,7 @@ uint8_t mget_result_function(memcached_st *memc) size_t key_length[]= {5, 3, 4}; unsigned int x; unsigned int counter; - unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *); + memcached_execute_function callbacks[1]; /* We need to empty the server before continueing test */ rc= memcached_flush(memc, 0); @@ -2414,6 +2431,7 @@ test_st tests[] ={ {"callback_test", 0, get_stats_keys }, {"version_string_test", 0, version_string_test}, {"bad_key", 1, bad_key_test }, + {"memcached_server_cursor", 1, memcached_server_cursor_test }, {0, 0, 0} };