From: Brian Aker Date: Tue, 5 Apr 2011 20:20:51 +0000 (-0700) Subject: Make sure query_id is allocated correctly. X-Git-Tag: 0.51~15^2~39 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e0da0f9b083d52e2f49e6759a8dc3868d0a4b8cf;p=m6w6%2Flibmemcached Make sure query_id is allocated correctly. --- diff --git a/libmemcached/error.c b/libmemcached/error.c index 86f58e60..357fda8c 100644 --- a/libmemcached/error.c +++ b/libmemcached/error.c @@ -40,6 +40,7 @@ struct memcached_error_st { memcached_st *root; + uint64_t query_id; struct memcached_error_st *next; memcached_return_t rc; int local_errno; @@ -47,18 +48,27 @@ struct memcached_error_st char c_str[]; }; -static memcached_error_st *_set(memcached_st *memc, memcached_string_t *str) +static void _set(memcached_st *memc, memcached_string_t *str, const memcached_return_t rc, const int local_errno) { + WATCHPOINT_ASSERT(memc); if (! memc) - return NULL; + return; + + if (memc->error_messages && memc->error_messages->query_id != memc->query_id) + { + memcached_error_free(memc); + } memcached_error_st *error; error= (struct memcached_error_st *)libmemcached_malloc(memc, sizeof(struct memcached_error_st) +(str ? str->size :0) +1); if (! error) - return NULL; + return; error->root= memc; + error->query_id= memc->query_id; + error->rc= rc; + error->local_errno= local_errno; if (str) { @@ -73,8 +83,6 @@ static memcached_error_st *_set(memcached_st *memc, memcached_string_t *str) error->next= memc->error_messages; memc->error_messages= error; - - return error; } memcached_return_t memcached_set_error_string(memcached_st *memc, memcached_return_t rc, const char *str, size_t length) @@ -90,28 +98,16 @@ memcached_return_t memcached_set_error(memcached_st *memc, memcached_return_t rc if (rc == MEMCACHED_SUCCESS) return MEMCACHED_SUCCESS; - memcached_error_st *error= _set(memc, str); - - if (error) - { - error->local_errno= 0; - error->rc= rc; - } + _set(memc, str, rc, 0); return rc; } memcached_return_t memcached_set_errno(memcached_st *memc, int local_errno, memcached_string_t *str) { - memcached_error_st *error= _set(memc, str); - - if (error) - { - error->local_errno= local_errno; - error->rc= MEMCACHED_ERRNO; - } + _set(memc, str, MEMCACHED_ERRNO, local_errno); - return error->rc; + return MEMCACHED_ERRNO; } static void _error_print(const memcached_error_st *error) diff --git a/libmemcached/error.h b/libmemcached/error.h index f8320802..c8b94806 100644 --- a/libmemcached/error.h +++ b/libmemcached/error.h @@ -65,7 +65,6 @@ LIBMEMCACHED_API LIBMEMCACHED_API int memcached_last_error_errno(memcached_st *memc); - #ifdef __cplusplus } // extern "C" #endif diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 3715f6eb..f3f3c4a6 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -87,6 +87,7 @@ static inline bool _memcached_init(memcached_st *self) self->snd_timeout= 0; self->rcv_timeout= 0; self->server_failure_limit= 0; + self->query_id= 0; /* TODO, Document why we picked these defaults */ self->io_msg_watermark= 500;