From bcceaba9c878bd4eb2ebd1d453fadbb1eec75092 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 24 Dec 2012 04:47:40 -0500 Subject: [PATCH] Cleanup style and possible errors, when calling stats. --- libmemcached/stats.cc | 82 ++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 29d9a425..43494948 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -389,7 +389,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, } memcached_server_response_decrement(instance); - do + while (1) { memcached_return_t rc= memcached_response(instance, buffer, sizeof(buffer), NULL); @@ -422,7 +422,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, WATCHPOINT_ASSERT(0); } } - } while (1); + } /* * memcached_response will decrement the counter, so I need to reset it.. @@ -587,6 +587,12 @@ memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char { memcached_st memc; + memcached_stat_st unused_memc_stat; + if (memc_stat == NULL) + { + memc_stat= &unused_memc_stat; + } + memset(memc_stat, 0, sizeof(memcached_stat_st)); memcached_st *memc_ptr= memcached_create(&memc); @@ -634,68 +640,72 @@ memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char We make a copy of the keys since at some point in the not so distant future we will add support for "found" keys. */ -char ** memcached_stat_get_keys(memcached_st *ptr, +char ** memcached_stat_get_keys(memcached_st *memc, memcached_stat_st *, memcached_return_t *error) { - if (ptr == NULL) + if (memc) { - return NULL; - } + char **list= static_cast(libmemcached_malloc(memc, sizeof(memcached_stat_keys))); + if (list == NULL) + { + if (error) + { + *error= memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + } - char **list= static_cast(libmemcached_malloc(ptr, sizeof(memcached_stat_keys))); - if (not list) - { - *error= memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); - return NULL; - } + return NULL; + } - memcpy(list, memcached_stat_keys, sizeof(memcached_stat_keys)); + memcpy(list, memcached_stat_keys, sizeof(memcached_stat_keys)); - *error= MEMCACHED_SUCCESS; + if (error) + { + *error= MEMCACHED_SUCCESS; + } + + return list; + } - return list; + return NULL; } void memcached_stat_free(const memcached_st *, memcached_stat_st *memc_stat) { WATCHPOINT_ASSERT(memc_stat); // Be polite, but when debugging catch this as an error - if (memc_stat == NULL) - { - return; - } - - if (memc_stat->root) + if (memc_stat) { libmemcached_free(memc_stat->root, memc_stat); - return; } - - libmemcached_free(NULL, memc_stat); } -static memcached_return_t call_stat_fn(memcached_st *ptr, +static memcached_return_t call_stat_fn(memcached_st *memc, org::libmemcached::Instance* instance, void *context) { - memcached_return_t rc; - local_context *check= (struct local_context *)context; - - if (memcached_is_binary(ptr)) - { - rc= binary_stats_fetch(NULL, check->args, check->args_length, instance, check); - } - else + if (memc) { - rc= ascii_stats_fetch(NULL, check->args, check->args_length, instance, check); + local_context *check= (struct local_context *)context; + + if (memcached_is_binary(memc)) + { + return binary_stats_fetch(NULL, check->args, check->args_length, instance, check); + } + else + { + return ascii_stats_fetch(NULL, check->args, check->args_length, instance, check); + } } - return rc; + return MEMCACHED_INVALID_ARGUMENTS; } memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context) { - memcached_version(memc); + if (memcached_fatal(memcached_version(memc))) + { + return memcached_last_error(memc); + } local_context check(func, context, args, args ? strlen(args) : 0); -- 2.30.2