From d5527716f9be29b67af8e978b02cc109a7b7bbc8 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sun, 27 Mar 2011 18:31:30 -0700 Subject: [PATCH] Move cached errno such that it now lives behind the API. --- clients/memcat.c | 4 ++-- clients/memcp.c | 4 ++-- clients/memdump.c | 4 ++-- clients/memflush.c | 4 ++-- clients/memrm.c | 5 +++-- libmemcached/behavior.c | 6 +++--- libmemcached/error.c | 6 +++--- libmemcached/error.h | 2 +- libmemcached/hosts.c | 2 +- libmemcached/io.c | 2 +- libmemcached/memcached.c | 1 - libmemcached/memcached.h | 1 - libmemcached/result.c | 7 +++---- libmemcached/result.h | 2 +- libmemcached/string.c | 4 ++-- libmemcached/string.h | 2 +- 16 files changed, 27 insertions(+), 29 deletions(-) diff --git a/clients/memcat.c b/clients/memcat.c index 8998ff0c..3f0d92b4 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -138,9 +138,9 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcat: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->cached_errno) + if (memcached_last_error_errno(memc)) { - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); } fprintf(stderr, "\n"); diff --git a/clients/memcp.c b/clients/memcp.c index bce35ce6..bf3828ae 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -188,8 +188,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memcp: %s: memcache error %s", ptr, memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); return_code= -1; diff --git a/clients/memdump.c b/clients/memdump.c index 67a2a540..0e81dad4 100644 --- a/clients/memdump.c +++ b/clients/memdump.c @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { fprintf(stderr, "memdump: memcache error %s", memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); } diff --git a/clients/memflush.c b/clients/memflush.c index 813bf9e1..848bc1e7 100644 --- a/clients/memflush.c +++ b/clients/memflush.c @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memflush: memcache error %s", memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); } diff --git a/clients/memrm.c b/clients/memrm.c index 8023a638..d4d93c2e 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -81,8 +81,8 @@ int main(int argc, char *argv[]) { fprintf(stderr, "memrm: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); - if (memc->cached_errno) - fprintf(stderr, " system error %s", strerror(memc->cached_errno)); + if (memcached_last_error_errno(memc)) + fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc))); fprintf(stderr, "\n"); return_code= -1; @@ -95,6 +95,7 @@ int main(int argc, char *argv[]) if (opt_servers) free(opt_servers); + if (opt_hash) free(opt_hash); diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index ab2c0230..48c6487f 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -198,7 +198,7 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, switch (enabled) { case MEM_FALSE: - return ptr->cached_errno ? MEMCACHED_ERRNO : MEMCACHED_FAILURE ; + return memcached_last_error_errno(ptr) ? MEMCACHED_ERRNO : MEMCACHED_FAILURE ; case MEM_TRUE: { enabled= test_cork(instance, false); @@ -321,7 +321,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_SNDBUF, &sock_size, &sock_length) < 0) { - ptr->cached_errno= errno; + memcached_set_errno(ptr, errno, NULL); return 0; /* Zero means error */ } } @@ -357,7 +357,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (getsockopt(instance->fd, SOL_SOCKET, SO_RCVBUF, &sock_size, &sock_length) < 0) { - ptr->cached_errno= errno; + memcached_set_errno(ptr, errno, NULL); return 0; /* Zero means error */ } diff --git a/libmemcached/error.c b/libmemcached/error.c index 81f6504d..86f58e60 100644 --- a/libmemcached/error.c +++ b/libmemcached/error.c @@ -191,13 +191,13 @@ memcached_return_t memcached_last_error(memcached_st *memc) return memc->error_messages->rc; } -memcached_return_t memcached_last_error_errno(memcached_st *memc) +int memcached_last_error_errno(memcached_st *memc) { if (! memc) - return MEMCACHED_INVALID_ARGUMENTS; + return 0; if (! memc->error_messages) - return MEMCACHED_SUCCESS; + return 0; return memc->error_messages->local_errno; } diff --git a/libmemcached/error.h b/libmemcached/error.h index d9a08dd7..f8320802 100644 --- a/libmemcached/error.h +++ b/libmemcached/error.h @@ -63,7 +63,7 @@ LIBMEMCACHED_API memcached_return_t memcached_last_error(memcached_st *memc); LIBMEMCACHED_API - memcached_return_t memcached_last_error_errno(memcached_st *memc); + int memcached_last_error_errno(memcached_st *memc); #ifdef __cplusplus diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 709d86fd..eb719708 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -119,7 +119,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (gettimeofday(&now, NULL) != 0) { - ptr->cached_errno = errno; + memcached_set_errno(ptr, errno, NULL); return MEMCACHED_ERRNO; } diff --git a/libmemcached/io.c b/libmemcached/io.c index dedcdaf9..5a9a7320 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -541,7 +541,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st int err= poll(fds, host_index, memc->poll_timeout); switch (err) { case -1: - memc->cached_errno = get_socket_errno(); + memcached_set_errno(memc, get_socket_errno(), NULL); /* FALLTHROUGH */ case 0: break; diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 8923a86d..8cacdc47 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -68,7 +68,6 @@ static inline bool _memcached_init(memcached_st *self) self->tcp_keepidle= 0; self->io_key_prefetch= 0; - self->cached_errno= 0; self->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; self->connect_timeout= MEMCACHED_DEFAULT_CONNECT_TIMEOUT; self->retry_timeout= 0; diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 622f9fb6..b2cb0bfd 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -99,7 +99,6 @@ struct memcached_st { uint32_t io_bytes_watermark; uint32_t io_key_prefetch; uint32_t tcp_keepidle; - int cached_errno; int32_t poll_timeout; int32_t connect_timeout; int32_t retry_timeout; diff --git a/libmemcached/result.c b/libmemcached/result.c index c6c754f3..6e58eebd 100644 --- a/libmemcached/result.c +++ b/libmemcached/result.c @@ -18,7 +18,7 @@ #include "common.h" static inline void _result_init(memcached_result_st *self, - const memcached_st *memc) + memcached_st *memc) { self->item_flags= 0; self->item_expiration= 0; @@ -50,9 +50,8 @@ memcached_result_st *memcached_result_create(const memcached_st *memc, ptr->options.is_initialized= true; - _result_init(ptr, memc); + _result_init(ptr, (memcached_st *)memc); - ptr->root= memc; WATCHPOINT_SET(ptr->value.options.is_initialized= false); memcached_string_create(memc, &ptr->value, 0); WATCHPOINT_ASSERT_INITIALIZED(&ptr->value); @@ -96,7 +95,7 @@ memcached_return_t memcached_result_set_value(memcached_result_st *ptr, if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) { - ((memcached_st *)ptr->root)->cached_errno= errno; + memcached_set_errno(ptr->root, errno, NULL); } return rc; diff --git a/libmemcached/result.h b/libmemcached/result.h index 46ea6eff..701b89b7 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -17,7 +17,7 @@ struct memcached_result_st { time_t item_expiration; size_t key_length; uint64_t item_cas; - const memcached_st *root; + memcached_st *root; memcached_string_st value; char item_key[MEMCACHED_MAX_KEY]; struct { diff --git a/libmemcached/string.c b/libmemcached/string.c index 34597067..b5badc5e 100644 --- a/libmemcached/string.c +++ b/libmemcached/string.c @@ -75,7 +75,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached self->options.is_allocated= true; } - self->root= memc; + self->root= (memcached_st *)memc; _init_string(self); @@ -84,7 +84,7 @@ memcached_string_st *memcached_string_create(const memcached_st *memc, memcached { if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) { - ((memcached_st *)memc)->cached_errno= errno; + memcached_set_errno(self->root, errno, NULL); } libmemcached_free(memc, self); diff --git a/libmemcached/string.h b/libmemcached/string.h index 77c55489..ca3dad14 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -27,7 +27,7 @@ struct memcached_string_st { char *end; char *string; size_t current_size; - const memcached_st *root; + memcached_st *root; struct { bool is_allocated:1; bool is_initialized:1; -- 2.30.2