From: Brian Aker Date: Sun, 7 Oct 2007 21:39:58 +0000 (-0700) Subject: Updated return code from memcached_response to send proper return to X-Git-Tag: 0.5~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=dcb04e7f4ecbe3d9aee892a551c793a7f2d809b4;p=m6w6%2Flibmemcached Updated return code from memcached_response to send proper return to memcached_stats(). Fixed memcached_stat to report accurate values. --- diff --git a/ChangeLog b/ChangeLog index 42a319c5..c14cabf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ * Fixed bug in multiple hosts not being activated * Added environmental variable MEMCACHED_SERVERS which can be used to set the servers list. + * fixed memcached_stat method (and now memstat works) 0.4 Wed Oct 3 10:28:50 PDT 2007 * Added buffered IO to write calls for keys diff --git a/include/memcached.h b/include/memcached.h index 1633872f..d687897a 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -66,6 +66,7 @@ typedef enum { MEMCACHED_END, MEMCACHED_DELETED, MEMCACHED_VALUE, + MEMCACHED_STAT, MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */ } memcached_return; diff --git a/lib/memcached_response.c b/lib/memcached_response.c index d649922b..5b0b7831 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -49,7 +49,7 @@ memcached_return memcached_response(memcached_st *ptr, case 'S': /* STORED STATS SERVER_ERROR */ { if (buffer[2] == 'A') /* STORED STATS */ - return MEMCACHED_SUCCESS; + return MEMCACHED_STAT; else if (buffer[1] == 'E') return MEMCACHED_SERVER_ERROR; else if (buffer[1] == 'T') diff --git a/lib/memcached_stats.c b/lib/memcached_stats.c index 644ca70d..b3a57812 100644 --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@ -222,7 +222,7 @@ static memcached_return memcached_stats_fetch(memcached_st *ptr, unsigned int server_key) { memcached_return rc; - char buffer[HUGE_STRING_LEN]; + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; size_t send_length, sent_length; rc= memcached_connect(ptr); @@ -231,10 +231,10 @@ static memcached_return memcached_stats_fetch(memcached_st *ptr, return rc; if (args) - send_length= snprintf(buffer, HUGE_STRING_LEN, + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats %s\r\n", args); else - send_length= snprintf(buffer, HUGE_STRING_LEN, + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats\r\n"); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) @@ -245,19 +245,17 @@ static memcached_return memcached_stats_fetch(memcached_st *ptr, if (sent_length == -1 || sent_length != send_length) return MEMCACHED_WRITE_FAILURE; - rc= memcached_response(ptr, buffer, HUGE_STRING_LEN, 0); - - if (rc == MEMCACHED_SUCCESS) + while (1) { - char *string_ptr, *end_ptr; - char *key, *value; + rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 0); - string_ptr= buffer; - while (1) + if (rc == MEMCACHED_STAT) { - if (memcmp(string_ptr, "STAT ", 5)) - break; - string_ptr+= 5; + char *string_ptr, *end_ptr; + char *key, *value; + + string_ptr= buffer; + string_ptr+= 5; /* Move past STAT */ for (end_ptr= string_ptr; *end_ptr != ' '; end_ptr++); key= string_ptr; key[(size_t)(end_ptr-string_ptr)]= 0; @@ -269,9 +267,14 @@ static memcached_return memcached_stats_fetch(memcached_st *ptr, string_ptr= end_ptr + 2; set_data(stat, key, value); } + else + break; } - return rc; + if (rc == MEMCACHED_END) + return MEMCACHED_SUCCESS; + else + return rc; } memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error) diff --git a/lib/memcached_strerror.c b/lib/memcached_strerror.c index 43c36a48..372cea23 100644 --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@ -52,6 +52,8 @@ char *memcached_strerror(memcached_st *ptr, memcached_return rc) return "SERVER DELETE"; case MEMCACHED_VALUE: return "SERVER VALUE"; + case MEMCACHED_STAT: + return "STAT VALUE"; case MEMCACHED_MAXIMUM_RETURN: return "Gibberish returned!"; default: diff --git a/src/memstat.c b/src/memstat.c index 40aade20..6b7f0ae5 100644 --- a/src/memstat.c +++ b/src/memstat.c @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) stat= memcached_stat(memc, NULL, &rc); - if (rc != MEMCACHED_SUCCESS && rc == MEMCACHED_SOME_ERRORS) + if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS) { printf("Failure to communicate with servers (%s)\n", memcached_strerror(memc, rc)); diff --git a/tests/output.res b/tests/output.res index c9171642..a3c5c628 100644 --- a/tests/output.res +++ b/tests/output.res @@ -23,6 +23,7 @@ Error 20 -> NO SERVERS DEFINED Error 21 -> SERVER END Error 22 -> SERVER DELETE Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE Found key pid Found key uptime Found key time @@ -125,6 +126,7 @@ Error 20 -> NO SERVERS DEFINED Error 21 -> SERVER END Error 22 -> SERVER DELETE Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE Found key pid Found key uptime Found key time @@ -227,6 +229,7 @@ Error 20 -> NO SERVERS DEFINED Error 21 -> SERVER END Error 22 -> SERVER DELETE Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE Found key pid Found key uptime Found key time @@ -329,6 +332,7 @@ Error 20 -> NO SERVERS DEFINED Error 21 -> SERVER END Error 22 -> SERVER DELETE Error 23 -> SERVER VALUE +Error 24 -> STAT VALUE Found key pid Found key uptime Found key time