X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fdump.cc;h=dcbe15b81c5104448b811880582215bf73fdb412;hb=3bc0498ee3f2fab34e4d4be1c6848dad30b76975;hp=d5aa292ae62104542e3abb1406581289b321d8e2;hpb=088eed04d829b8cf6591201564118c356d3cf935;p=m6w6%2Flibmemcached diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index d5aa292a..dcbe15b8 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -6,38 +6,37 @@ all slabs on servers and "grab" the keys. */ -#include "common.h" +#include + static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) { memcached_return_t rc= MEMCACHED_SUCCESS; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - uint32_t server_key; - uint32_t x; - - unlikely (memcached_server_count(ptr) == 0) - return MEMCACHED_NO_SERVERS; - for (server_key= 0; server_key < memcached_server_count(ptr); server_key++) + for (uint32_t server_key= 0; server_key < memcached_server_count(ptr); server_key++) { memcached_server_write_instance_st instance; instance= memcached_server_instance_fetch(ptr, server_key); /* 256 I BELIEVE is the upper limit of slabs */ - for (x= 0; x < 256; x++) + for (uint32_t x= 0; x < 256; x++) { + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; int send_length; send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats cachedump %u 0 0\r\n", x); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) { - return MEMCACHED_FAILURE; + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, + memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)")); } rc= memcached_do(instance, buffer, (size_t)send_length, true); - unlikely (rc != MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) + { goto error; + } while (1) { @@ -47,23 +46,29 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb if (rc == MEMCACHED_ITEM) { char *string_ptr, *end_ptr; - char *key; string_ptr= buffer; string_ptr+= 5; /* Move past ITEM */ + for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {} ; - key= string_ptr; + + char *key= string_ptr; key[(size_t)(end_ptr-string_ptr)]= 0; + for (callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++) { rc= (*callback[callback_counter])(ptr, key, (size_t)(end_ptr-string_ptr), context); if (rc != MEMCACHED_SUCCESS) + { break; + } } } else if (rc == MEMCACHED_END) + { break; - else if (rc == MEMCACHED_SERVER_ERROR || rc == MEMCACHED_CLIENT_ERROR) + } + else if (rc == MEMCACHED_SERVER_ERROR or rc == MEMCACHED_CLIENT_ERROR) { /* If we try to request stats cachedump for a slab class that is too big * the server will return an incorrect error message: @@ -76,16 +81,22 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb break; } else + { goto error; + } } } } error: if (rc == MEMCACHED_END) + { return MEMCACHED_SUCCESS; + } else + { return rc; + } } memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) @@ -101,7 +112,9 @@ memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback @todo Fix this so that we just flush, switch to ascii, and then go back to binary. */ if (ptr->flags.binary_protocol) + { return MEMCACHED_FAILURE; + } return ascii_dump(ptr, callback, context, number_of_callbacks); }