From 6566056f5c7061162828fef2469c41ebd2521b5c Mon Sep 17 00:00:00 2001 From: Matt Knox Date: Mon, 29 Jun 2009 13:51:23 -0700 Subject: [PATCH] cached the server error in memcached_server_st --- libmemcached/memcached_response.c | 11 ++++++++++- libmemcached/memcached_server.c | 24 ++++++++++++++++++++---- libmemcached/memcached_server.h | 1 + 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libmemcached/memcached_response.c b/libmemcached/memcached_response.c index 1ea0c725..e1720f0a 100644 --- a/libmemcached/memcached_response.c +++ b/libmemcached/memcached_response.c @@ -238,7 +238,16 @@ static memcached_return textual_read_one_response(memcached_server_st *ptr, return MEMCACHED_STAT; } else if (buffer[1] == 'E') - return MEMCACHED_SERVER_ERROR; + { + /* SERVER_ERROR */ + char *startptr= buffer + 13, *endptr= startptr; + while (*endptr != '\r' && *endptr != '\n') endptr++; + if (ptr->cached_server_error) free(ptr->cached_server_error); + ptr->cached_server_error= malloc(endptr - startptr + 1); + memcpy(ptr->cached_server_error, startptr, endptr - startptr); + ptr->cached_server_error[endptr - startptr]= 0; + return MEMCACHED_SERVER_ERROR; + } else if (buffer[1] == 'T') return MEMCACHED_STORED; else diff --git a/libmemcached/memcached_server.c b/libmemcached/memcached_server.c index 04364f3a..2359611e 100644 --- a/libmemcached/memcached_server.c +++ b/libmemcached/memcached_server.c @@ -53,6 +53,12 @@ void memcached_server_free(memcached_server_st *ptr) { memcached_quit_server(ptr, 0); + if (ptr->cached_server_error) + { + free(ptr->cached_server_error); + ptr->cached_server_error= NULL; + } + if (ptr->address_info) { freeaddrinfo(ptr->address_info); @@ -70,14 +76,24 @@ void memcached_server_free(memcached_server_st *ptr) */ memcached_server_st *memcached_server_clone(memcached_server_st *clone, memcached_server_st *ptr) { + memcached_server_st *rv = NULL; + /* We just do a normal create if ptr is missing */ if (ptr == NULL) return NULL; - /* TODO We should check return type */ - return memcached_server_create_with(ptr->root, clone, - ptr->hostname, ptr->port, ptr->weight, - ptr->type); + rv = memcached_server_create_with(ptr->root, clone, + ptr->hostname, ptr->port, ptr->weight, + ptr->type); + if (rv != NULL) + { + rv->cached_errno= ptr->cached_errno; + if (ptr->cached_server_error) + rv->cached_server_error= strdup(ptr->cached_server_error); + } + + return rv; + } memcached_return memcached_server_cursor(memcached_st *ptr, diff --git a/libmemcached/memcached_server.h b/libmemcached/memcached_server.h index 1d68f24e..cffc5e80 100644 --- a/libmemcached/memcached_server.h +++ b/libmemcached/memcached_server.h @@ -21,6 +21,7 @@ struct memcached_server_st { unsigned int port; int cached_errno; int fd; + char *cached_server_error; uint32_t io_bytes_sent; /* # bytes sent since last read */ uint32_t server_failure_counter; uint32_t weight; -- 2.30.2