From 79892ee7f064bbbb7768ec7ed700655da2c35275 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sun, 16 Dec 2007 22:59:04 -0800 Subject: [PATCH] Refactor (1st piece) of logic around creating messages and recieving messages. --- include/memcached.h | 4 +++- lib/memcached_delete.c | 1 - lib/memcached_do.c | 2 ++ lib/memcached_fetch.c | 1 - lib/memcached_get.c | 5 +++-- lib/memcached_response.c | 29 +++++++++++++++++++++++++---- lib/memcached_storage.c | 6 +----- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/include/memcached.h b/include/memcached.h index 182d6992..1e2d3b3f 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -199,8 +199,10 @@ struct memcached_st { memcached_hash hash; memcached_server_distribution distribution; unsigned int wheel[MEMCACHED_WHEEL_SIZE]; +#ifdef NOT_USED /* Future Use */ uint8_t replicas; - memcached_return warning; /* Future Use */ + memcached_return warning; +#endif }; /* Public API */ diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index 7c026cbc..f68d7340 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -54,7 +54,6 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, if ((ptr->flags & MEM_NO_BLOCK)) { rc= MEMCACHED_SUCCESS; - memcached_server_response_increment(ptr, server_key); } else { diff --git a/lib/memcached_do.c b/lib/memcached_do.c index ce9cceb6..a929927c 100644 --- a/lib/memcached_do.c +++ b/lib/memcached_do.c @@ -19,6 +19,8 @@ memcached_return memcached_do(memcached_st *ptr, unsigned int server_key, char * if (sent_length == -1 || sent_length != command_length) rc= MEMCACHED_WRITE_FAILURE; + else + memcached_server_response_increment(ptr, server_key); return rc; } diff --git a/lib/memcached_fetch.c b/lib/memcached_fetch.c index 4f6a575c..b6161845 100644 --- a/lib/memcached_fetch.c +++ b/lib/memcached_fetch.c @@ -21,7 +21,6 @@ static memcached_return memcached_value_fetch(memcached_st *ptr, char *key, size rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); - if (rc == MEMCACHED_SUCCESS) { char *next_ptr; diff --git a/lib/memcached_get.c b/lib/memcached_get.c index 63a981e1..ffb2c5f6 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -103,7 +103,7 @@ memcached_return memcached_mget_by_key(memcached_st *ptr, rc= MEMCACHED_SOME_ERRORS; continue; } - ptr->hosts[server_key].cursor_active= 1; + ptr->hosts[server_key].cursor_active++; } if ((memcached_io_write(ptr, server_key, keys[x], key_length[x], 0)) == -1) @@ -126,13 +126,14 @@ memcached_return memcached_mget_by_key(memcached_st *ptr, */ for (x= 0; x < ptr->number_of_hosts; x++) { - if (ptr->hosts[x].cursor_active == 1) + if (ptr->hosts[x].cursor_active) { /* We need to doo something about non-connnected hosts in the future */ if ((memcached_io_write(ptr, x, "\r\n", 2, 1)) == -1) { rc= MEMCACHED_SOME_ERRORS; } + memcached_server_response_increment(ptr, x); } } diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 7402975f..a695e9d8 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -21,7 +21,7 @@ memcached_return memcached_response(memcached_st *ptr, send_length= 0; max_messages= memcached_server_response_count(ptr, server_key); - for (x= 0; x <= max_messages; x++) + for (x= 0; x < max_messages; x++) { size_t total_length= 0; buffer_ptr= buffer; @@ -50,26 +50,47 @@ memcached_return memcached_response(memcached_st *ptr, buffer_ptr++; *buffer_ptr= 0; - if (memcached_server_response_count(ptr, server_key)) - memcached_server_response_decrement(ptr, server_key); + memcached_server_response_decrement(ptr, server_key); } switch(buffer[0]) { case 'V': /* VALUE || VERSION */ - return MEMCACHED_SUCCESS; + if (buffer[1] == 'A') /* VALUE */ + { + /* We add back in one because we will need to search for END */ + memcached_server_response_increment(ptr, server_key); + return MEMCACHED_SUCCESS; + } + else if (buffer[1] == 'E') /* VERSION */ + { + return MEMCACHED_SUCCESS; + } + else + { + WATCHPOINT_STRING(buffer); + WATCHPOINT_ASSERT(0); + return MEMCACHED_UNKNOWN_READ_FAILURE; + } case 'O': /* OK */ return MEMCACHED_SUCCESS; case 'S': /* STORED STATS SERVER_ERROR */ { if (buffer[2] == 'A') /* STORED STATS */ + { + memcached_server_response_increment(ptr, server_key); return MEMCACHED_STAT; + } else if (buffer[1] == 'E') return MEMCACHED_SERVER_ERROR; else if (buffer[1] == 'T') return MEMCACHED_STORED; else + { + WATCHPOINT_STRING(buffer); + WATCHPOINT_ASSERT(0); return MEMCACHED_UNKNOWN_READ_FAILURE; + } } case 'D': /* DELETED */ return MEMCACHED_DELETED; diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 3f55796d..5f694135 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -108,14 +108,10 @@ static inline memcached_return memcached_send(memcached_st *ptr, } if (to_write == 0) - { rc= MEMCACHED_SUCCESS; - memcached_server_response_increment(ptr, server_key); - } else - { rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); - } + if (rc == MEMCACHED_STORED) return MEMCACHED_SUCCESS; else -- 2.30.2