From 2be01b67cdfd2cda7f623492650898896f57e978 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 22 Dec 2011 00:34:24 -0800 Subject: [PATCH] Convert stats to vector. --- libmemcached/response.cc | 16 +++++++--- libmemcached/stats.cc | 69 +++++++++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 061f7401..775102fa 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -184,7 +184,9 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st value_length= (size_t)strtoull(next_ptr, &string_ptr, 10); if (end_ptr == string_ptr) + { goto read_error; + } /* Skip spaces */ if (*string_ptr == '\r') @@ -388,13 +390,19 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta default: { - unsigned long long auto_return_value; + unsigned long long int auto_return_value= strtoull(buffer, (char **)NULL, 10); - if (sscanf(buffer, "%llu", &auto_return_value) == 1) - return MEMCACHED_SUCCESS; + if (auto_return_value == ULLONG_MAX and errno == ERANGE) + { + return MEMCACHED_UNKNOWN_READ_FAILURE; + } + else if (errno == EINVAL) + { + return MEMCACHED_UNKNOWN_READ_FAILURE; + } WATCHPOINT_STRING(buffer); - return MEMCACHED_UNKNOWN_READ_FAILURE; + return MEMCACHED_SUCCESS; } } diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 239c789d..ac49c937 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -1,7 +1,40 @@ -/* -*/ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ -#include "common.h" +#include static const char *memcached_stat_keys[] = { "pid", @@ -53,7 +86,7 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char WATCHPOINT_STRING(key); return MEMCACHED_UNKNOWN_STAT_KEY; } - else if (not strcmp("pid", key)) + else if (strcmp("pid", key) == 0) { int64_t temp= strtoll(value, (char **)NULL, 10); @@ -400,27 +433,23 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, memcached_server_write_instance_st instance, struct local_context *check) { - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - int send_length; - + int send_length= 0; if (args) { - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats %s\r\n", args); - } - else - { - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats\r\n"); + send_length= strlen(args); } - if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) + struct libmemcached_io_vector_st vector[]= { - return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, - memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)")); - } + { memcached_literal_param("stats ") }, + { args, send_length }, + { memcached_literal_param("\r\n") } + }; - memcached_return_t rc= memcached_do(instance, buffer, (size_t)send_length, true); + memcached_return_t rc= memcached_vdo(instance, vector, 3, true); if (memcached_success(rc)) { + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; while ((rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL)) == MEMCACHED_STAT) { char *string_ptr, *end_ptr; @@ -456,9 +485,11 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, } if (rc == MEMCACHED_END) + { return MEMCACHED_SUCCESS; - else - return rc; + } + + return rc; } memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error) -- 2.30.2