From dac169cdb8e544f5967bb8d22f229b49d78afa9a Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 22 Mar 2011 19:23:44 -0700 Subject: [PATCH] Additional cleanup on error messages. --- libmemcached/behavior.c | 16 ++++++++++++- libmemcached/behavior.h | 3 +++ libmemcached/options/parser.yy | 41 +++++++++++++++++----------------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index b687eac5..138e0f17 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -489,6 +489,20 @@ const char *libmemcached_string_behavior(const memcached_behavior_t flag) case MEMCACHED_BEHAVIOR_TCP_KEEPIDLE: return "MEMCACHED_BEHAVIOR_TCP_KEEPIDLE"; case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE: return "MEMCACHED_BEHAVIOR_LOAD_FROM_FILE"; default: - case MEMCACHED_BEHAVIOR_MAX: return "INVALID BEHAVIOR"; + case MEMCACHED_BEHAVIOR_MAX: return "INVALID memcached_behavior_t"; + } +} + +const char *libmemcached_string_distribution(const memcached_server_distribution_t flag) +{ + switch (flag) + { + case MEMCACHED_DISTRIBUTION_MODULA: return "MEMCACHED_DISTRIBUTION_MODULA"; + case MEMCACHED_DISTRIBUTION_CONSISTENT: return "MEMCACHED_DISTRIBUTION_CONSISTENT"; + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA"; + case MEMCACHED_DISTRIBUTION_RANDOM: return "MEMCACHED_DISTRIBUTION_RANDOM"; + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: return "MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY"; + default: + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: return "INVALID memcached_server_distribution_t"; } } diff --git a/libmemcached/behavior.h b/libmemcached/behavior.h index c5f855ee..1c8d42e2 100644 --- a/libmemcached/behavior.h +++ b/libmemcached/behavior.h @@ -46,6 +46,9 @@ bool _is_auto_eject_host(const memcached_st *ptr); LIBMEMCACHED_LOCAL const char *libmemcached_string_behavior(const memcached_behavior_t flag); +LIBMEMCACHED_LOCAL + const char *libmemcached_string_distribution(const memcached_server_distribution_t flag); + #ifdef __cplusplus } #endif diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index 20f17c75..92902c26 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -179,10 +179,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_callback_set(parser->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS) { - std::string error_message("--PREFIX-KEY"); - error_message.append($3.c_str, $3.length); - memcached_string_t tmp= memcached_string_make(error_message.c_str(), error_message.size()); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--PREFIX-KEY" << $3; + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -191,8 +190,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS) { - memcached_string_t tmp= memcached_string_make(memcached_string_with_size("--DISTRIBUTION")); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--DISTRIBUTION=" << libmemcached_string_distribution($3); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -201,11 +201,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS) { - std::string buffer; - buffer+= "--HASH="; - buffer+= libmemcached_string_hash($3); - memcached_string_t tmp= memcached_string_make(buffer.c_str(), buffer.size()); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--HASH=" << libmemcached_string_hash($3); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -214,8 +212,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS) { - memcached_string_t tmp= memcached_string_make(memcached_string_with_size("--KETAMA-HASH")); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--KETAMA-HASH=" << libmemcached_string_hash($3); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -224,8 +223,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_behavior_set(parser->memc, $1, $3)) != MEMCACHED_SUCCESS) { - memcached_string_t tmp= memcached_string_make(libmemcached_string_behavior($1), strlen(libmemcached_string_behavior($1))); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--" << libmemcached_string_behavior($1) << "=" << $3; + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -234,8 +234,9 @@ behaviors: memcached_return_t rc; if ((rc= memcached_behavior_set(parser->memc, $1, true)) != MEMCACHED_SUCCESS) { - memcached_string_t tmp= memcached_string_make(libmemcached_string_behavior($1), strlen(libmemcached_string_behavior($1))); - memcached_set_error(parser->memc, rc, &tmp); + std::stringstream ss; + ss << "--" << libmemcached_string_behavior($1); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -374,8 +375,7 @@ server_list: { std::stringstream ss; ss << "--SERVER=" << $1; - memcached_string_t tmp= memcached_string_make(ss.str().c_str(), ss.str().length()); - memcached_set_error(parser->memc, rc, &tmp); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } @@ -386,8 +386,7 @@ server_list: { std::stringstream ss; ss << "--SERVERS=" << $3; - memcached_string_t tmp= memcached_string_make(ss.str().c_str(), ss.str().length()); - memcached_set_error(parser->memc, rc, &tmp); + memcached_set_error_string(parser->memc, rc, ss.str().c_str(), ss.str().length()); YYERROR; } } -- 2.30.2