From 326e812b0ca940bf90aaadf69312a0316091d0cb Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 14 Jan 2013 05:17:30 -0500 Subject: [PATCH] Abstraction (which will save us merge hell with 1.2). --- libmemcached/allocators.cc | 58 +++++++------- libmemcached/analyze.cc | 3 +- libmemcached/auto.cc | 16 ++-- libmemcached/behavior.cc | 125 ++++++++++++++++++++----------- libmemcached/callback.cc | 95 ++++++++++++----------- libmemcached/common.h | 1 + libmemcached/delete.cc | 7 +- libmemcached/dump.cc | 5 +- libmemcached/encoding_key.cc | 5 +- libmemcached/error.cc | 14 ++-- libmemcached/exist.cc | 7 +- libmemcached/fetch.cc | 6 +- libmemcached/flush.cc | 7 +- libmemcached/flush_buffers.cc | 36 +++++---- libmemcached/get.cc | 9 ++- libmemcached/hash.cc | 42 ++++++++--- libmemcached/hosts.cc | 111 ++++++++++++++------------- libmemcached/initialize_query.cc | 4 +- libmemcached/instance.cc | 18 +++-- libmemcached/io.cc | 6 +- libmemcached/is.h | 2 + libmemcached/memcached.cc | 76 +++++++++++-------- libmemcached/purge.cc | 8 +- libmemcached/quit.cc | 5 +- libmemcached/response.cc | 2 +- libmemcached/result.cc | 8 +- libmemcached/sasl.cc | 26 +++++-- libmemcached/server.cc | 8 +- libmemcached/stats.cc | 9 ++- libmemcached/storage.cc | 7 +- libmemcached/string.cc | 2 +- libmemcached/touch.cc | 3 +- libmemcached/verbosity.cc | 9 ++- libmemcached/version.cc | 7 +- 34 files changed, 443 insertions(+), 304 deletions(-) diff --git a/libmemcached/allocators.cc b/libmemcached/allocators.cc index e1c9d780..f1caf71e 100644 --- a/libmemcached/allocators.cc +++ b/libmemcached/allocators.cc @@ -77,13 +77,14 @@ struct memcached_allocator_t memcached_allocators_return_default(void) return global_default_allocator; } -memcached_return_t memcached_set_memory_allocators(memcached_st *self, +memcached_return_t memcached_set_memory_allocators(memcached_st *shell, memcached_malloc_fn mem_malloc, memcached_free_fn mem_free, memcached_realloc_fn mem_realloc, memcached_calloc_fn mem_calloc, void *context) { + Memcached* self= memcached2Memcached(shell); if (self == NULL) { return MEMCACHED_INVALID_ARGUMENTS; @@ -110,39 +111,44 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, return MEMCACHED_SUCCESS; } -void *memcached_get_memory_allocators_context(const memcached_st *self) +void *memcached_get_memory_allocators_context(const memcached_st *shell) { - return self->allocators.context; + const Memcached* self= memcached2Memcached(shell); + if (self) + { + return self->allocators.context; + } + + return NULL; } -void memcached_get_memory_allocators(const memcached_st *self, +void memcached_get_memory_allocators(const memcached_st *shell, memcached_malloc_fn *mem_malloc, memcached_free_fn *mem_free, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc) { - if (self == NULL) - { - return; - } - - if (mem_malloc) - { - *mem_malloc= self->allocators.malloc; - } - - if (mem_free) - { - *mem_free= self->allocators.free; - } - - if (mem_realloc) - { - *mem_realloc= self->allocators.realloc; - } - - if (mem_calloc) + const Memcached* self= memcached2Memcached(shell); + if (self) { - *mem_calloc= self->allocators.calloc; + if (mem_malloc) + { + *mem_malloc= self->allocators.malloc; + } + + if (mem_free) + { + *mem_free= self->allocators.free; + } + + if (mem_realloc) + { + *mem_realloc= self->allocators.realloc; + } + + if (mem_calloc) + { + *mem_calloc= self->allocators.calloc; + } } } diff --git a/libmemcached/analyze.cc b/libmemcached/analyze.cc index 03c7e85b..c6ac15c2 100644 --- a/libmemcached/analyze.cc +++ b/libmemcached/analyze.cc @@ -61,10 +61,11 @@ static void calc_hit_ratio(memcached_analysis_st *result, result->pool_hit_ratio= temp * 100; } -memcached_analysis_st *memcached_analyze(memcached_st *memc, +memcached_analysis_st *memcached_analyze(memcached_st *shell, memcached_stat_st *memc_stat, memcached_return_t *error) { + Memcached* memc= memcached2Memcached(shell); uint64_t total_items= 0, total_bytes= 0; uint64_t total_get_cmds= 0, total_get_hits= 0; diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index f9f84d7b..57d6d2fd 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -151,7 +151,7 @@ memcached_return_t memcached_increment(memcached_st *memc, } static memcached_return_t increment_decrement_by_key(const protocol_binary_command command, - memcached_st *memc, + Memcached *memc, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, @@ -206,7 +206,7 @@ static memcached_return_t increment_decrement_by_key(const protocol_binary_comma } static memcached_return_t increment_decrement_with_initial_by_key(const protocol_binary_command command, - memcached_st *memc, + Memcached *memc, const char *group_key, size_t group_key_length, const char *key, @@ -272,12 +272,13 @@ memcached_return_t memcached_decrement(memcached_st *memc, } -memcached_return_t memcached_increment_by_key(memcached_st *memc, +memcached_return_t memcached_increment_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t *value) { + Memcached* memc= memcached2Memcached(shell); LIBMEMCACHED_MEMCACHED_INCREMENT_START(); memcached_return_t rc= increment_decrement_by_key(PROTOCOL_BINARY_CMD_INCREMENT, memc, @@ -290,12 +291,13 @@ memcached_return_t memcached_increment_by_key(memcached_st *memc, return rc; } -memcached_return_t memcached_decrement_by_key(memcached_st *memc, +memcached_return_t memcached_decrement_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t *value) { + Memcached* memc= memcached2Memcached(shell); LIBMEMCACHED_MEMCACHED_DECREMENT_START(); memcached_return_t rc= increment_decrement_by_key(PROTOCOL_BINARY_CMD_DECREMENT, memc, @@ -320,7 +322,7 @@ memcached_return_t memcached_increment_with_initial(memcached_st *memc, offset, initial, expiration, value); } -memcached_return_t memcached_increment_with_initial_by_key(memcached_st *memc, +memcached_return_t memcached_increment_with_initial_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, @@ -331,6 +333,7 @@ memcached_return_t memcached_increment_with_initial_by_key(memcached_st *memc, uint64_t *value) { LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); + Memcached* memc= memcached2Memcached(shell); memcached_return_t rc= increment_decrement_with_initial_by_key(PROTOCOL_BINARY_CMD_INCREMENT, memc, group_key, group_key_length, @@ -354,7 +357,7 @@ memcached_return_t memcached_decrement_with_initial(memcached_st *memc, offset, initial, expiration, value); } -memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *memc, +memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, @@ -365,6 +368,7 @@ memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *memc, uint64_t *value) { LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START(); + Memcached* memc= memcached2Memcached(shell); memcached_return_t rc= increment_decrement_with_initial_by_key(PROTOCOL_BINARY_CMD_DECREMENT, memc, group_key, group_key_length, diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 33926c83..7a8b9853 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -42,7 +42,7 @@ #include #include -bool memcached_is_consistent_distribution(const memcached_st* memc) +bool memcached_is_consistent_distribution(const Memcached* memc) { switch (memc->distribution) { @@ -68,10 +68,11 @@ bool memcached_is_consistent_distribution(const memcached_st* memc) We quit all connections so we can reset the sockets. */ -memcached_return_t memcached_behavior_set(memcached_st *ptr, +memcached_return_t memcached_behavior_set(memcached_st *shell, const memcached_behavior_t flag, uint64_t data) { + Memcached* ptr= memcached2Memcached(shell); if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; @@ -308,9 +309,10 @@ bool _is_auto_eject_host(const memcached_st *ptr) return ptr->flags.auto_eject_hosts; } -uint64_t memcached_behavior_get(memcached_st *ptr, +uint64_t memcached_behavior_get(memcached_st *shell, const memcached_behavior_t flag) { + Memcached* ptr= memcached2Memcached(shell); if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; @@ -513,77 +515,113 @@ uint64_t memcached_behavior_get(memcached_st *ptr, } -memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcached_server_distribution_t type) +memcached_return_t memcached_behavior_set_distribution(memcached_st *shell, memcached_server_distribution_t type) { - switch (type) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - case MEMCACHED_DISTRIBUTION_MODULA: - break; + switch (type) + { + case MEMCACHED_DISTRIBUTION_MODULA: + break; - case MEMCACHED_DISTRIBUTION_CONSISTENT: - case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: - memcached_set_weighted_ketama(ptr, false); - break; + case MEMCACHED_DISTRIBUTION_CONSISTENT: + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: + memcached_set_weighted_ketama(ptr, false); + break; - case MEMCACHED_DISTRIBUTION_RANDOM: - break; + case MEMCACHED_DISTRIBUTION_RANDOM: + break; - case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: - break; + case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: + break; - case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: - memcached_set_weighted_ketama(ptr, true); - break; + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: + memcached_set_weighted_ketama(ptr, true); + break; - case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: - break; + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: + break; - default: - case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("Invalid memcached_server_distribution_t")); + default: + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("Invalid memcached_server_distribution_t")); + } + ptr->distribution= type; + + return run_distribution(ptr); } - ptr->distribution= type; - return run_distribution(ptr); + return MEMCACHED_INVALID_ARGUMENTS; } -memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st *ptr) +memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st *shell) { - return ptr->distribution; + Memcached* ptr= memcached2Memcached(shell); + if (ptr) + { + return ptr->distribution; + } + + return MEMCACHED_DISTRIBUTION_CONSISTENT_MAX; } -memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type) +memcached_return_t memcached_behavior_set_key_hash(memcached_st *shell, memcached_hash_t type) { - if (hashkit_success(hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type))) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - return MEMCACHED_SUCCESS; + if (hashkit_success(hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type))) + { + return MEMCACHED_SUCCESS; + } + + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("Invalid memcached_hash_t()")); } - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("Invalid memcached_hash_t()")); + return MEMCACHED_INVALID_ARGUMENTS; } -memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr) +memcached_hash_t memcached_behavior_get_key_hash(memcached_st *shell) { - return (memcached_hash_t)hashkit_get_function(&ptr->hashkit); + Memcached* ptr= memcached2Memcached(shell); + if (ptr) + { + return (memcached_hash_t)hashkit_get_function(&ptr->hashkit); + } + + return MEMCACHED_HASH_MAX; } -memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type) +memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *shell, memcached_hash_t type) { - if (hashkit_success(hashkit_set_distribution_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type))) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - return MEMCACHED_SUCCESS; + if (hashkit_success(hashkit_set_distribution_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type))) + { + return MEMCACHED_SUCCESS; + } + + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("Invalid memcached_hash_t()")); } - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("Invalid memcached_hash_t()")); + return MEMCACHED_INVALID_ARGUMENTS; } -memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr) +memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *shell) { - return (memcached_hash_t)hashkit_get_function(&ptr->hashkit); + Memcached* ptr= memcached2Memcached(shell); + if (ptr) + { + return (memcached_hash_t)hashkit_get_function(&ptr->hashkit); + } + + return MEMCACHED_HASH_MAX; } const char *libmemcached_string_behavior(const memcached_behavior_t flag) @@ -648,12 +686,13 @@ const char *libmemcached_string_distribution(const memcached_server_distribution } } -memcached_return_t memcached_bucket_set(memcached_st *self, +memcached_return_t memcached_bucket_set(memcached_st *shell, const uint32_t *host_map, const uint32_t *forward_map, const uint32_t buckets, const uint32_t replicas) { + Memcached* self= memcached2Memcached(shell); memcached_return_t rc; if (self == NULL) diff --git a/libmemcached/callback.cc b/libmemcached/callback.cc index 3d87f98d..bb001feb 100644 --- a/libmemcached/callback.cc +++ b/libmemcached/callback.cc @@ -20,75 +20,82 @@ These functions provide data and function callback support */ -memcached_return_t memcached_callback_set(memcached_st *ptr, +memcached_return_t memcached_callback_set(memcached_st *shell, const memcached_callback_t flag, const void *data) { - switch (flag) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - case MEMCACHED_CALLBACK_PREFIX_KEY: + switch (flag) { - return memcached_set_namespace(ptr, (char*)data, data ? strlen((char*)data) : 0); - } + case MEMCACHED_CALLBACK_PREFIX_KEY: + { + return memcached_set_namespace(ptr, (char*)data, data ? strlen((char*)data) : 0); + } - case MEMCACHED_CALLBACK_USER_DATA: - { - ptr->user_data= const_cast(data); - break; - } + case MEMCACHED_CALLBACK_USER_DATA: + { + ptr->user_data= const_cast(data); + break; + } - case MEMCACHED_CALLBACK_CLEANUP_FUNCTION: - { - memcached_cleanup_fn func= *(memcached_cleanup_fn *)&data; - ptr->on_cleanup= func; - break; - } + case MEMCACHED_CALLBACK_CLEANUP_FUNCTION: + { + memcached_cleanup_fn func= *(memcached_cleanup_fn *)&data; + ptr->on_cleanup= func; + break; + } - case MEMCACHED_CALLBACK_CLONE_FUNCTION: - { - memcached_clone_fn func= *(memcached_clone_fn *)&data; - ptr->on_clone= func; - break; - } + case MEMCACHED_CALLBACK_CLONE_FUNCTION: + { + memcached_clone_fn func= *(memcached_clone_fn *)&data; + ptr->on_clone= func; + break; + } - case MEMCACHED_CALLBACK_GET_FAILURE: - { - memcached_trigger_key_fn func= *(memcached_trigger_key_fn *)&data; - ptr->get_key_failure= func; - break; - } + case MEMCACHED_CALLBACK_GET_FAILURE: + { + memcached_trigger_key_fn func= *(memcached_trigger_key_fn *)&data; + ptr->get_key_failure= func; + break; + } - case MEMCACHED_CALLBACK_DELETE_TRIGGER: - { - if (data) // NULL would mean we are disabling. + case MEMCACHED_CALLBACK_DELETE_TRIGGER: { - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) + if (data) // NULL would mean we are disabling. { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if buffering is enabled")); + if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if buffering is enabled")); + } + + if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_NOREPLY)) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if MEMCACHED_BEHAVIOR_NOREPLY is set")); + } } - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_NOREPLY)) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if MEMCACHED_BEHAVIOR_NOREPLY is set")); - } + memcached_trigger_delete_key_fn func= *(memcached_trigger_delete_key_fn *)&data; + ptr->delete_trigger= func; + break; } - memcached_trigger_delete_key_fn func= *(memcached_trigger_delete_key_fn *)&data; - ptr->delete_trigger= func; - break; + case MEMCACHED_CALLBACK_MAX: + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid callback supplied")); } - case MEMCACHED_CALLBACK_MAX: - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid callback supplied")); + return MEMCACHED_SUCCESS; } - return MEMCACHED_SUCCESS; + return MEMCACHED_INVALID_ARGUMENTS; } -void *memcached_callback_get(memcached_st *ptr, +void *memcached_callback_get(memcached_st *shell, const memcached_callback_t flag, memcached_return_t *error) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t local_error; if (error == NULL) { diff --git a/libmemcached/common.h b/libmemcached/common.h index b03f79c1..c7b84c94 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -114,6 +114,7 @@ #include #include #include +typedef struct memcached_st Memcached; #ifdef __cplusplus # include "libmemcached/instance.hpp" diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 8b4ca76a..67957f45 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -38,10 +38,10 @@ #include #include -memcached_return_t memcached_delete(memcached_st *memc, const char *key, size_t key_length, +memcached_return_t memcached_delete(memcached_st *shell, const char *key, size_t key_length, time_t expiration) { - return memcached_delete_by_key(memc, key, key_length, key, key_length, expiration); + return memcached_delete_by_key(shell, key, key_length, key, key_length, expiration); } static inline memcached_return_t ascii_delete(org::libmemcached::Instance* instance, @@ -135,11 +135,12 @@ static inline memcached_return_t binary_delete(org::libmemcached::Instance* inst return rc; } -memcached_return_t memcached_delete_by_key(memcached_st *memc, +memcached_return_t memcached_delete_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration) { + Memcached* memc= memcached2Memcached(shell); LIBMEMCACHED_MEMCACHED_DELETE_START(); memcached_return_t rc; diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index 13c2580a..35da13f5 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -44,7 +44,7 @@ #include -static memcached_return_t ascii_dump(memcached_st *memc, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) +static memcached_return_t ascii_dump(Memcached *memc, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) { /* MAX_NUMBER_OF_SLAB_CLASSES is defined to 200 in Memcached 1.4.10 */ for (uint32_t x= 0; x < 200; x++) @@ -137,8 +137,9 @@ static memcached_return_t ascii_dump(memcached_st *memc, memcached_dump_fn *call return memcached_has_current_error(*memc) ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; } -memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) +memcached_return_t memcached_dump(memcached_st *shell, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(ptr, true))) { diff --git a/libmemcached/encoding_key.cc b/libmemcached/encoding_key.cc index 3472029c..5888d439 100644 --- a/libmemcached/encoding_key.cc +++ b/libmemcached/encoding_key.cc @@ -38,13 +38,14 @@ #include #include -static void _set_encoding_key(memcached_st& self, const char *key, size_t key_length) +static void _set_encoding_key(Memcached& self, const char *key, size_t key_length) { hashkit_key(&self.hashkit, key, key_length); } -memcached_return_t memcached_set_encoding_key(memcached_st* self, const char *key, size_t key_length) +memcached_return_t memcached_set_encoding_key(memcached_st* shell, const char *key, size_t key_length) { + Memcached* self= memcached2Memcached(shell); if (self == NULL) { return MEMCACHED_INVALID_ARGUMENTS; diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 4c6bfc06..85326780 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -50,7 +50,7 @@ struct memcached_error_t char message[MAX_ERROR_LENGTH]; }; -static void _set(org::libmemcached::Instance& server, memcached_st& memc) +static void _set(org::libmemcached::Instance& server, Memcached& memc) { if (server.error_messages and server.error_messages->query_id != server.root->query_id) { @@ -467,8 +467,9 @@ static void _error_print(const memcached_error_t *error) _error_print(error->next); } -void memcached_error_print(const memcached_st *self) +void memcached_error_print(const memcached_st *shell) { + const Memcached* self= memcached2Memcached(shell); if (self == NULL) { return; @@ -517,8 +518,9 @@ const char *memcached_error(const memcached_st *memc) return memcached_last_error_message(memc); } -const char *memcached_last_error_message(const memcached_st *memc) +const char *memcached_last_error_message(const memcached_st *shell) { + const Memcached* memc= memcached2Memcached(shell); if (memc) { if (memc->error_messages) @@ -554,8 +556,9 @@ bool memcached_has_current_error(org::libmemcached::Instance& server) return memcached_has_current_error(*(server.root)); } -memcached_return_t memcached_last_error(const memcached_st *memc) +memcached_return_t memcached_last_error(const memcached_st *shell) { + const Memcached* memc= memcached2Memcached(shell); if (memc) { if (memc->error_messages) @@ -569,8 +572,9 @@ memcached_return_t memcached_last_error(const memcached_st *memc) return MEMCACHED_INVALID_ARGUMENTS; } -int memcached_last_error_errno(const memcached_st *memc) +int memcached_last_error_errno(const memcached_st *shell) { + const Memcached* memc= memcached2Memcached(shell); if (memc == NULL) { return 0; diff --git a/libmemcached/exist.cc b/libmemcached/exist.cc index 56c1efce..8ed60545 100644 --- a/libmemcached/exist.cc +++ b/libmemcached/exist.cc @@ -36,7 +36,7 @@ #include -static memcached_return_t ascii_exist(memcached_st *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length) +static memcached_return_t ascii_exist(Memcached *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length) { libmemcached_io_vector_st vector[]= { @@ -74,7 +74,7 @@ static memcached_return_t ascii_exist(memcached_st *memc, org::libmemcached::Ins return rc; } -static memcached_return_t binary_exist(memcached_st *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length) +static memcached_return_t binary_exist(Memcached *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length) { protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); @@ -127,10 +127,11 @@ memcached_return_t memcached_exist(memcached_st *memc, const char *key, size_t k return memcached_exist_by_key(memc, key, key_length, key, key_length); } -memcached_return_t memcached_exist_by_key(memcached_st *memc, +memcached_return_t memcached_exist_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length) { + Memcached* memc= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(memc, true))) { diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index ff729f9e..8eef0c78 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -37,11 +37,12 @@ #include -char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, +char *memcached_fetch(memcached_st *shell, char *key, size_t *key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t unused; if (error == NULL) { @@ -252,11 +253,12 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, return NULL; } -memcached_return_t memcached_fetch_execute(memcached_st *ptr, +memcached_return_t memcached_fetch_execute(memcached_st *shell, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks) { + Memcached* ptr= memcached2Memcached(shell); memcached_result_st *result= &ptr->result; memcached_return_t rc; bool some_errors= false; diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index 7a102eab..521515ac 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -36,7 +36,7 @@ #include -static memcached_return_t memcached_flush_binary(memcached_st *ptr, +static memcached_return_t memcached_flush_binary(Memcached *ptr, time_t expiration, const bool reply) { @@ -95,7 +95,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, return rc; } -static memcached_return_t memcached_flush_textual(memcached_st *ptr, +static memcached_return_t memcached_flush_textual(Memcached *ptr, time_t expiration, const bool reply) { @@ -147,8 +147,9 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, return rc; } -memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration) +memcached_return_t memcached_flush(memcached_st *shell, time_t expiration) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(ptr, true))) { diff --git a/libmemcached/flush_buffers.cc b/libmemcached/flush_buffers.cc index af6942b4..3fa935c8 100644 --- a/libmemcached/flush_buffers.cc +++ b/libmemcached/flush_buffers.cc @@ -37,29 +37,35 @@ #include -memcached_return_t memcached_flush_buffers(memcached_st *memc) +memcached_return_t memcached_flush_buffers(memcached_st *shell) { - memcached_return_t ret= MEMCACHED_SUCCESS; - - for (uint32_t x= 0; x < memcached_server_count(memc); ++x) + Memcached* memc= memcached2Memcached(shell); + if (memc) { - org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); + memcached_return_t ret= MEMCACHED_SUCCESS; - if (instance->write_buffer_offset != 0) + for (uint32_t x= 0; x < memcached_server_count(memc); ++x) { - if (instance->fd == INVALID_SOCKET and - (ret= memcached_connect(instance)) != MEMCACHED_SUCCESS) - { - WATCHPOINT_ERROR(ret); - return ret; - } + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); - if (memcached_io_write(instance) == false) + if (instance->write_buffer_offset != 0) { - ret= MEMCACHED_SOME_ERRORS; + if (instance->fd == INVALID_SOCKET and + (ret= memcached_connect(instance)) != MEMCACHED_SUCCESS) + { + WATCHPOINT_ERROR(ret); + return ret; + } + + if (memcached_io_write(instance) == false) + { + ret= MEMCACHED_SOME_ERRORS; + } } } + + return ret; } - return ret; + return MEMCACHED_INVALID_ARGUMENTS; } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 7d273176..2a25d788 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -58,7 +58,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, size_t number_of_keys, bool mget_mode); -char *memcached_get_by_key(memcached_st *ptr, +char *memcached_get_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, @@ -66,6 +66,7 @@ char *memcached_get_by_key(memcached_st *ptr, uint32_t *flags, memcached_return_t *error) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t unused; if (error == NULL) { @@ -385,13 +386,14 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, return MEMCACHED_FAILURE; // Complete failure occurred } -memcached_return_t memcached_mget_by_key(memcached_st *ptr, +memcached_return_t memcached_mget_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys) { + Memcached* ptr= memcached2Memcached(shell); return memcached_mget_by_key_real(ptr, group_key, group_key_length, keys, key_length, number_of_keys, true); } @@ -409,7 +411,7 @@ memcached_return_t memcached_mget_execute(memcached_st *ptr, context, number_of_callbacks); } -memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr, +memcached_return_t memcached_mget_execute_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char * const *keys, @@ -419,6 +421,7 @@ memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr, void *context, unsigned int number_of_callbacks) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(ptr, false))) { diff --git a/libmemcached/hash.cc b/libmemcached/hash.cc index 42e46989..4e02312e 100644 --- a/libmemcached/hash.cc +++ b/libmemcached/hash.cc @@ -47,12 +47,12 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca return libhashkit_digest(key, key_length, (hashkit_hash_algorithm_t)hash_algorithm); } -static inline uint32_t generate_hash(const memcached_st *ptr, const char *key, size_t key_length) +static inline uint32_t generate_hash(const Memcached *ptr, const char *key, size_t key_length) { return hashkit_digest(&ptr->hashkit, key, key_length); } -static uint32_t dispatch_host(const memcached_st *ptr, uint32_t hash) +static uint32_t dispatch_host(const Memcached *ptr, uint32_t hash) { switch (ptr->distribution) { @@ -99,7 +99,7 @@ static uint32_t dispatch_host(const memcached_st *ptr, uint32_t hash) /* One version is public and will not modify the distribution hash, the other will. */ -static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const char *key, size_t key_length) +static inline uint32_t _generate_hash_wrapper(const Memcached *ptr, const char *key, size_t key_length) { WATCHPOINT_ASSERT(memcached_server_count(ptr)); @@ -125,7 +125,7 @@ static inline uint32_t _generate_hash_wrapper(const memcached_st *ptr, const cha } } -static inline void _regen_for_auto_eject(memcached_st *ptr) +static inline void _regen_for_auto_eject(Memcached *ptr) { if (_is_auto_eject_host(ptr) && ptr->ketama.next_distribution_rebuild) { @@ -153,22 +153,40 @@ uint32_t memcached_generate_hash_with_redistribution(memcached_st *ptr, const ch return dispatch_host(ptr, hash); } -uint32_t memcached_generate_hash(const memcached_st *ptr, const char *key, size_t key_length) +uint32_t memcached_generate_hash(const memcached_st *shell, const char *key, size_t key_length) { - return dispatch_host(ptr, _generate_hash_wrapper(ptr, key, key_length)); + const Memcached* ptr= memcached2Memcached(shell); + if (ptr) + { + return dispatch_host(ptr, _generate_hash_wrapper(ptr, key, key_length)); + } + + return UINT32_MAX; } -const hashkit_st *memcached_get_hashkit(const memcached_st *ptr) +const hashkit_st *memcached_get_hashkit(const memcached_st *shell) { - return &ptr->hashkit; + const Memcached* ptr= memcached2Memcached(shell); + if (ptr) + { + return &ptr->hashkit; + } + + return NULL; } -memcached_return_t memcached_set_hashkit(memcached_st *self, hashkit_st *hashk) +memcached_return_t memcached_set_hashkit(memcached_st *shell, hashkit_st *hashk) { - hashkit_free(&self->hashkit); - hashkit_clone(&self->hashkit, hashk); + Memcached* self= memcached2Memcached(shell); + if (self) + { + hashkit_free(&self->hashkit); + hashkit_clone(&self->hashkit, hashk); + + return MEMCACHED_SUCCESS; + } - return MEMCACHED_SUCCESS; + return MEMCACHED_INVALID_ARGUMENTS; } const char * libmemcached_string_hash(memcached_hash_t type) diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 80ba0339..20677694 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -42,7 +42,7 @@ #include /* Protoypes (static) */ -static memcached_return_t update_continuum(memcached_st *ptr); +static memcached_return_t update_continuum(Memcached *ptr); static int compare_servers(const void *p1, const void *p2) { @@ -59,7 +59,7 @@ static int compare_servers(const void *p1, const void *p2) return return_value; } -static void sort_hosts(memcached_st *ptr) +static void sort_hosts(Memcached *ptr) { if (memcached_server_count(ptr)) { @@ -68,7 +68,7 @@ static void sort_hosts(memcached_st *ptr) } -memcached_return_t run_distribution(memcached_st *ptr) +memcached_return_t run_distribution(Memcached *ptr) { if (ptr->flags.use_sort_hosts) { @@ -132,7 +132,7 @@ static int continuum_item_cmp(const void *t1, const void *t2) } } -static memcached_return_t update_continuum(memcached_st *ptr) +static memcached_return_t update_continuum(Memcached *ptr) { uint32_t continuum_index= 0; uint32_t pointer_counter= 0; @@ -346,7 +346,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) return MEMCACHED_SUCCESS; } -static memcached_return_t server_add(memcached_st *memc, +static memcached_return_t server_add(Memcached *memc, const memcached_string_t& hostname, in_port_t port, uint32_t weight, @@ -395,52 +395,58 @@ static memcached_return_t server_add(memcached_st *memc, } -memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) +memcached_return_t memcached_server_push(memcached_st *shell, const memcached_server_list_st list) { if (list == NULL) { return MEMCACHED_SUCCESS; } - uint32_t original_host_size= memcached_server_count(ptr); - uint32_t count= memcached_server_list_count(list); - uint32_t host_list_size= count +original_host_size; - - org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), host_list_size, org::libmemcached::Instance); - - if (new_host_list == NULL) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - } + uint32_t original_host_size= memcached_server_count(ptr); + uint32_t count= memcached_server_list_count(list); + uint32_t host_list_size= count +original_host_size; - memcached_instance_set(ptr, new_host_list, host_list_size); + org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), host_list_size, org::libmemcached::Instance); - ptr->state.is_parsing= true; - for (uint32_t x= 0; x < count; ++x, ++original_host_size) - { - WATCHPOINT_ASSERT(list[x].hostname[0] != 0); - - // We have extended the array, and now we will find it, and use it. - org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, original_host_size); - WATCHPOINT_ASSERT(instance); - - memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; - if (__instance_create_with(ptr, instance, - hostname, - list[x].port, list[x].weight, list[x].type) == NULL) + if (new_host_list == NULL) { - ptr->state.is_parsing= false; - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; } - if (list[x].weight > 1) + memcached_instance_set(ptr, new_host_list, host_list_size); + + ptr->state.is_parsing= true; + for (uint32_t x= 0; x < count; ++x, ++original_host_size) { - memcached_set_weighted_ketama(ptr, true); + WATCHPOINT_ASSERT(list[x].hostname[0] != 0); + + // We have extended the array, and now we will find it, and use it. + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, original_host_size); + WATCHPOINT_ASSERT(instance); + + memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; + if (__instance_create_with(ptr, instance, + hostname, + list[x].port, list[x].weight, list[x].type) == NULL) + { + ptr->state.is_parsing= false; + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + } + + if (list[x].weight > 1) + { + memcached_set_weighted_ketama(ptr, true); + } } + ptr->state.is_parsing= false; + + return run_distribution(ptr); } - ptr->state.is_parsing= false; - return run_distribution(ptr); + return MEMCACHED_INVALID_ARGUMENTS; } memcached_return_t memcached_instance_push(memcached_st *ptr, const struct org::libmemcached::Instance* list, uint32_t number_of_hosts) @@ -499,22 +505,23 @@ memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, return memcached_server_add_unix_socket_with_weight(ptr, filename, 0); } -memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr, +memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *shell, const char *filename, uint32_t weight) { - if (ptr == NULL) + Memcached* ptr= memcached2Memcached(shell); + if (ptr) { - return MEMCACHED_FAILURE; - } + memcached_string_t _filename= { memcached_string_make_from_cstr(filename) }; + if (memcached_is_valid_filename(_filename) == false) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid filename for socket provided")); + } - memcached_string_t _filename= { memcached_string_make_from_cstr(filename) }; - if (memcached_is_valid_filename(_filename) == false) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid filename for socket provided")); + return server_add(ptr, _filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); } - return server_add(ptr, _filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); + return MEMCACHED_FAILURE; } memcached_return_t memcached_server_add_udp(memcached_st *ptr, @@ -524,31 +531,33 @@ memcached_return_t memcached_server_add_udp(memcached_st *ptr, return memcached_server_add_udp_with_weight(ptr, hostname, port, 0); } -memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, +memcached_return_t memcached_server_add_udp_with_weight(memcached_st *shell, const char *, in_port_t, uint32_t) { - if (ptr == NULL) + Memcached* self= memcached2Memcached(shell); + if (self) { - return MEMCACHED_INVALID_ARGUMENTS; + return memcached_set_error(*self, MEMCACHED_DEPRECATED, MEMCACHED_AT); } - return memcached_set_error(*ptr, MEMCACHED_DEPRECATED, MEMCACHED_AT); + return MEMCACHED_INVALID_ARGUMENTS; } -memcached_return_t memcached_server_add(memcached_st *ptr, +memcached_return_t memcached_server_add(memcached_st *shell, const char *hostname, in_port_t port) { - return memcached_server_add_with_weight(ptr, hostname, port, 0); + return memcached_server_add_with_weight(shell, hostname, port, 0); } -memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, +memcached_return_t memcached_server_add_with_weight(memcached_st *shell, const char *hostname, in_port_t port, uint32_t weight) { + Memcached* ptr= memcached2Memcached(shell); if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; diff --git a/libmemcached/initialize_query.cc b/libmemcached/initialize_query.cc index 0a4aae07..cef8e575 100644 --- a/libmemcached/initialize_query.cc +++ b/libmemcached/initialize_query.cc @@ -36,7 +36,7 @@ #include -memcached_return_t initialize_query(memcached_st *self, bool increment_query_id) +memcached_return_t initialize_query(Memcached *self, bool increment_query_id) { if (self == NULL) { @@ -64,7 +64,7 @@ memcached_return_t initialize_query(memcached_st *self, bool increment_query_id) return MEMCACHED_SUCCESS; } -memcached_return_t initialize_const_query(const memcached_st *self) +memcached_return_t initialize_const_query(const Memcached *self) { if (self == NULL) { diff --git a/libmemcached/instance.cc b/libmemcached/instance.cc index faad235d..593465d8 100644 --- a/libmemcached/instance.cc +++ b/libmemcached/instance.cc @@ -37,7 +37,7 @@ #include -static inline void _server_init(org::libmemcached::Instance* self, memcached_st *root, +static inline void _server_init(org::libmemcached::Instance* self, Memcached *root, const memcached_string_t& hostname, in_port_t port, uint32_t weight, memcached_connection_t type) @@ -195,11 +195,12 @@ void memcached_instance_free(org::libmemcached::Instance* self) } } -memcached_return_t memcached_server_cursor(const memcached_st* memc, +memcached_return_t memcached_server_cursor(const memcached_st* shell, const memcached_server_fn *callback, void *context, uint32_t number_of_callbacks) { + const Memcached* memc= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_const_query(memc))) { @@ -255,11 +256,12 @@ memcached_return_t memcached_server_execute(memcached_st *memc, return MEMCACHED_SUCCESS; } -memcached_server_instance_st memcached_server_by_key(memcached_st *memc, +memcached_server_instance_st memcached_server_by_key(memcached_st *shell, const char *key, size_t key_length, memcached_return_t *error) { + Memcached* memc= memcached2Memcached(shell); memcached_return_t unused; if (error == NULL) { @@ -328,15 +330,15 @@ void set_last_disconnected_host(org::libmemcached::Instance* self) } } -memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self) +memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *shell) { - WATCHPOINT_ASSERT(self); - if (self == NULL) + const Memcached* self= memcached2Memcached(shell); + if (self) { - return 0; + return (memcached_server_instance_st)self->last_disconnected_server; } - return (memcached_server_instance_st)self->last_disconnected_server; + return 0; } void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time) diff --git a/libmemcached/io.cc b/libmemcached/io.cc index 60614f5c..20233c7d 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -148,10 +148,10 @@ static bool process_input_buffer(org::libmemcached::Instance* instance) */ memcached_callback_st cb= *instance->root->callbacks; - memcached_set_processing_input((memcached_st *)instance->root, true); + memcached_set_processing_input((Memcached *)instance->root, true); char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - memcached_st *root= (memcached_st *)instance->root; + Memcached *root= (Memcached *)instance->root; memcached_return_t error= memcached_response(instance, buffer, sizeof(buffer), &root->result); memcached_set_processing_input(root, false); @@ -746,7 +746,7 @@ void org::libmemcached::Instance::close_socket() major_version= minor_version= micro_version= UINT8_MAX; } -org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc, memcached_return_t&) +org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, memcached_return_t&) { #define MAX_SERVERS_TO_POLL 100 struct pollfd fds[MAX_SERVERS_TO_POLL]; diff --git a/libmemcached/is.h b/libmemcached/is.h index cf56f65f..54f2c2b2 100644 --- a/libmemcached/is.h +++ b/libmemcached/is.h @@ -91,3 +91,5 @@ #define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated= (__value)) #define memcached_set_weighted_ketama(__object, __value) ((__object)->ketama.weighted_= (__value)) + +#define memcached2Memcached(__obj) (__obj) diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index bd23f1f1..932b8986 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -40,7 +40,7 @@ #include #include -static inline bool _memcached_init(memcached_st *self) +static inline bool _memcached_init(Memcached *self) { self->state.is_purging= false; self->state.is_processing_input= false; @@ -127,7 +127,7 @@ static inline bool _memcached_init(memcached_st *self) return true; } -static void __memcached_free(memcached_st *ptr, bool release_st) +static void __memcached_free(Memcached *ptr, bool release_st) { /* If we have anything open, lets close it now */ send_quit(ptr); @@ -170,8 +170,9 @@ static void __memcached_free(memcached_st *ptr, bool release_st) } } -memcached_st *memcached_create(memcached_st *ptr) +memcached_st *memcached_create(memcached_st *shell) { + Memcached* ptr= memcached2Memcached(shell); if (ptr) { ptr->options.is_allocated= false; @@ -252,8 +253,9 @@ memcached_st *memcached(const char *string, size_t length) return memc; } -memcached_return_t memcached_reset(memcached_st *ptr) +memcached_return_t memcached_reset(memcached_st *shell) { + Memcached* ptr= memcached2Memcached(shell); WATCHPOINT_ASSERT(ptr); if (ptr == NULL) { @@ -275,8 +277,9 @@ memcached_return_t memcached_reset(memcached_st *ptr) return MEMCACHED_SUCCESS; } -void memcached_servers_reset(memcached_st *self) +void memcached_servers_reset(memcached_st *shell) { + Memcached* self= memcached2Memcached(shell); if (self) { libmemcached_free(self, self->ketama.continuum); @@ -289,8 +292,9 @@ void memcached_servers_reset(memcached_st *self) } } -void memcached_reset_last_disconnected_server(memcached_st *self) +void memcached_reset_last_disconnected_server(memcached_st *shell) { + Memcached* self= memcached2Memcached(shell); if (self) { memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server); @@ -401,27 +405,29 @@ memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source) return new_clone; } -void *memcached_get_user_data(const memcached_st *ptr) +void *memcached_get_user_data(const memcached_st *shell) { - if (ptr == NULL) + const Memcached* memc= memcached2Memcached(shell); + if (memc) { - return NULL; + return memc->user_data; } - return ptr->user_data; + return NULL; } -void *memcached_set_user_data(memcached_st *ptr, void *data) +void *memcached_set_user_data(memcached_st *shell, void *data) { - if (ptr == NULL) + Memcached* memc= memcached2Memcached(shell); + if (memc) { - return NULL; - } + void *ret= memc->user_data; + memc->user_data= data; - void *ret= ptr->user_data; - ptr->user_data= data; + return ret; + } - return ret; + return NULL; } memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source) @@ -429,7 +435,7 @@ memcached_return_t memcached_push(memcached_st *destination, const memcached_st return memcached_instance_push(destination, (org::libmemcached::Instance*)source->servers, source->number_of_hosts); } -org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key) +org::libmemcached::Instance* memcached_instance_fetch(Memcached *ptr, uint32_t server_key) { if (ptr == NULL) { @@ -439,41 +445,45 @@ org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_ return &ptr->servers[server_key]; } -memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key) +memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *shell, uint32_t server_key) { - if (ptr == NULL) + const Memcached* memc= memcached2Memcached(shell); + if (memc) { - return NULL; + return &memc->servers[server_key]; } - return &ptr->servers[server_key]; + return NULL; } -org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key) +org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *shell, uint32_t server_key) { - if (ptr == NULL) + const Memcached* memc= memcached2Memcached(shell); + if (memc) { - return NULL; + return &memc->servers[server_key]; } - return &ptr->servers[server_key]; + return NULL; } -uint64_t memcached_query_id(const memcached_st *self) +uint64_t memcached_query_id(const memcached_st *shell) { - if (self == NULL) + const Memcached* memc= memcached2Memcached(shell); + if (memc) { - return 0; + return memc->query_id; } - return self->query_id; + return 0; } -org::libmemcached::Instance* memcached_instance_list(const memcached_st *self) +org::libmemcached::Instance* memcached_instance_list(const memcached_st *shell) { - if (self) + const Memcached* memc= memcached2Memcached(shell); + if (memc) { - return (org::libmemcached::Instance*)self->servers; + return (org::libmemcached::Instance*)memc->servers; } return NULL; diff --git a/libmemcached/purge.cc b/libmemcached/purge.cc index b45e02a4..b1390d9c 100644 --- a/libmemcached/purge.cc +++ b/libmemcached/purge.cc @@ -44,7 +44,7 @@ class Purge { public: - Purge(memcached_st* arg) : + Purge(Memcached* arg) : _memc(arg) { memcached_set_purging(_memc, true); @@ -56,13 +56,13 @@ public: } private: - memcached_st* _memc; + Memcached* _memc; }; class PollTimeout { public: - PollTimeout(memcached_st* arg) : + PollTimeout(Memcached* arg) : _timeout(arg->poll_timeout), _origin(arg->poll_timeout) { @@ -81,7 +81,7 @@ private: bool memcached_purge(org::libmemcached::Instance* ptr) { - memcached_st *root= (memcached_st *)ptr->root; + Memcached *root= (Memcached *)ptr->root; if (memcached_is_purging(ptr->root) || /* already purging */ (memcached_server_response_count(ptr) < ptr->root->io_msg_watermark && diff --git a/libmemcached/quit.cc b/libmemcached/quit.cc index 8b33255b..61930beb 100644 --- a/libmemcached/quit.cc +++ b/libmemcached/quit.cc @@ -126,7 +126,7 @@ void memcached_quit_server(org::libmemcached::Instance* instance, bool io_death) } } -void send_quit(memcached_st *memc) +void send_quit(Memcached *memc) { for (uint32_t x= 0; x < memcached_server_count(memc); x++) { @@ -136,8 +136,9 @@ void send_quit(memcached_st *memc) } } -void memcached_quit(memcached_st *memc) +void memcached_quit(memcached_st *shell) { + Memcached* memc= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(memc, true))) { diff --git a/libmemcached/response.cc b/libmemcached/response.cc index cb0e682b..cf7ed41e 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -805,7 +805,7 @@ static memcached_return_t _read_one_response(org::libmemcached::Instance* instan if (result == NULL) { - memcached_st *root= (memcached_st *)instance->root; + Memcached *root= (Memcached *)instance->root; result = &root->result; } diff --git a/libmemcached/result.cc b/libmemcached/result.cc index c3e0b452..6fa507b2 100644 --- a/libmemcached/result.cc +++ b/libmemcached/result.cc @@ -2,7 +2,7 @@ * * Libmemcached library * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/ * Copyright (C) 2006-2009 Brian Aker All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ #include static inline void _result_init(memcached_result_st *self, - memcached_st *memc) + Memcached *memc) { self->item_flags= 0; self->item_expiration= 0; @@ -57,10 +57,10 @@ static inline void _result_init(memcached_result_st *self, self->item_key[0]= 0; } -memcached_result_st *memcached_result_create(const memcached_st *memc, +memcached_result_st *memcached_result_create(const memcached_st *shell, memcached_result_st *ptr) { - WATCHPOINT_ASSERT(memc); + const Memcached* memc= memcached2Memcached(shell); /* Saving malloc calls :) */ if (ptr) diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index e4738069..69d6223d 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -46,16 +46,26 @@ #include -void memcached_set_sasl_callbacks(memcached_st *ptr, +void memcached_set_sasl_callbacks(memcached_st *shell, const sasl_callback_t *callbacks) { - ptr->sasl.callbacks= const_cast(callbacks); - ptr->sasl.is_allocated= false; + Memcached* self= memcached2Memcached(shell); + if (self) + { + self->sasl.callbacks= const_cast(callbacks); + self->sasl.is_allocated= false; + } } -sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr) +sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *shell) { - return ptr->sasl.callbacks; + Memcached* self= memcached2Memcached(shell); + if (self) + { + return self->sasl.callbacks; + } + + return NULL; } /** @@ -310,10 +320,11 @@ static int get_password(sasl_conn_t *conn, void *context, int id, return SASL_OK; } -memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, +memcached_return_t memcached_set_sasl_auth_data(memcached_st *shell, const char *username, const char *password) { + Memcached* ptr= memcached2Memcached(shell); if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) { return MEMCACHED_NOT_SUPPORTED; @@ -367,13 +378,14 @@ memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, return MEMCACHED_SUCCESS; } -memcached_return_t memcached_destroy_sasl_auth_data(memcached_st *ptr) +memcached_return_t memcached_destroy_sasl_auth_data(memcached_st *shell) { if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) { return MEMCACHED_NOT_SUPPORTED; } + Memcached* ptr= memcached2Memcached(shell); if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; diff --git a/libmemcached/server.cc b/libmemcached/server.cc index 20db52b8..27e51e96 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -40,7 +40,7 @@ */ #include -static inline void _server_init(memcached_server_st *self, memcached_st *root, +static inline void _server_init(memcached_server_st *self, Memcached *root, const memcached_string_t& hostname, in_port_t port, uint32_t weight, memcached_connection_t type) @@ -82,7 +82,7 @@ static inline void _server_init(memcached_server_st *self, memcached_st *root, self->hostname[hostname.size]= 0; } -static memcached_server_st *_server_create(memcached_server_st *self, const memcached_st *memc) +static memcached_server_st *_server_create(memcached_server_st *self, const Memcached *memc) { if (self == NULL) { @@ -105,7 +105,7 @@ static memcached_server_st *_server_create(memcached_server_st *self, const memc return self; } -memcached_server_st *__server_create_with(memcached_st *memc, +memcached_server_st *__server_create_with(Memcached *memc, memcached_server_st* allocated_instance, const memcached_string_t& hostname, const in_port_t port, @@ -125,7 +125,7 @@ memcached_server_st *__server_create_with(memcached_st *memc, return NULL; } - _server_init(allocated_instance, const_cast(memc), hostname, port, weight, type); + _server_init(allocated_instance, const_cast(memc), hostname, port, weight, type); return allocated_instance; } diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 6bab673d..89d5be52 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -514,8 +514,9 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, return rc; } -memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error) +memcached_stat_st *memcached_stat(memcached_st *shell, char *args, memcached_return_t *error) { + Memcached* self= memcached2Memcached(shell); memcached_return_t unused; if (error == NULL) { @@ -652,10 +653,11 @@ memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char We make a copy of the keys since at some point in the not so distant future we will add support for "found" keys. */ -char ** memcached_stat_get_keys(memcached_st *memc, +char ** memcached_stat_get_keys(memcached_st *shell, memcached_stat_st *, memcached_return_t *error) { + Memcached* memc= memcached2Memcached(shell); if (memc) { char **list= static_cast(libmemcached_malloc(memc, sizeof(memcached_stat_keys))); @@ -712,8 +714,9 @@ static memcached_return_t call_stat_fn(memcached_st *memc, return MEMCACHED_INVALID_ARGUMENTS; } -memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context) +memcached_return_t memcached_stat_execute(memcached_st *shell, const char *args, memcached_stat_fn func, void *context) { + Memcached* memc= memcached2Memcached(shell); if (memcached_fatal(memcached_version(memc))) { return memcached_last_error(memc); diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index e17b7609..558d2ed5 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -138,7 +138,7 @@ static inline uint8_t get_com_code(const memcached_storage_action_t verb, const return PROTOCOL_BINARY_CMD_SET; } -static memcached_return_t memcached_send_binary(memcached_st *ptr, +static memcached_return_t memcached_send_binary(Memcached *ptr, org::libmemcached::Instance* server, uint32_t server_key, const char *key, @@ -245,7 +245,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, return memcached_response(server, NULL, 0, NULL); } -static memcached_return_t memcached_send_ascii(memcached_st *ptr, +static memcached_return_t memcached_send_ascii(Memcached *ptr, org::libmemcached::Instance* instance, const char *key, const size_t key_length, @@ -351,7 +351,7 @@ static memcached_return_t memcached_send_ascii(memcached_st *ptr, return rc; } -static inline memcached_return_t memcached_send(memcached_st *ptr, +static inline memcached_return_t memcached_send(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, const char *value, size_t value_length, @@ -360,6 +360,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, const uint64_t cas, memcached_storage_action_t verb) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(ptr, true))) { diff --git a/libmemcached/string.cc b/libmemcached/string.cc index 89b33e11..7826bd10 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -79,7 +79,7 @@ static inline void _init_string(memcached_string_st *self) self->end= self->string= NULL; } -memcached_string_st *memcached_string_create(memcached_st *memc, memcached_string_st *self, size_t initial_size) +memcached_string_st *memcached_string_create(Memcached *memc, memcached_string_st *self, size_t initial_size) { WATCHPOINT_ASSERT(memc); diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index 7a8c7cee..0c24aed1 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -110,11 +110,12 @@ memcached_return_t memcached_touch(memcached_st *ptr, return memcached_touch_by_key(ptr, key, key_length, key, key_length, expiration); } -memcached_return_t memcached_touch_by_key(memcached_st *ptr, +memcached_return_t memcached_touch_by_key(memcached_st *shell, const char *group_key, size_t group_key_length, const char *key, size_t key_length, time_t expiration) { + Memcached* ptr= memcached2Memcached(shell); LIBMEMCACHED_MEMCACHED_TOUCH_START(); memcached_return_t rc; diff --git a/libmemcached/verbosity.cc b/libmemcached/verbosity.cc index 4a9918d2..7f3a16e4 100644 --- a/libmemcached/verbosity.cc +++ b/libmemcached/verbosity.cc @@ -43,14 +43,14 @@ struct context_st const char *buffer; }; -static memcached_return_t _set_verbosity(const memcached_st *, +static memcached_return_t _set_verbosity(const Memcached *, const memcached_server_instance_st server, void *context) { libmemcached_io_vector_st *vector= (libmemcached_io_vector_st *)context; - memcached_st local_memc; - memcached_st *memc_ptr= memcached_create(&local_memc); + Memcached local_memc; + Memcached *memc_ptr= memcached_create(&local_memc); memcached_return_t rc= memcached_server_add(memc_ptr, memcached_server_name(server), memcached_server_port(server)); @@ -73,8 +73,9 @@ static memcached_return_t _set_verbosity(const memcached_st *, return rc; } -memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity) +memcached_return_t memcached_verbosity(memcached_st *shell, uint32_t verbosity) { + Memcached* ptr= memcached2Memcached(shell); memcached_return_t rc; if (memcached_failed(rc= initialize_query(ptr, false))) { diff --git a/libmemcached/version.cc b/libmemcached/version.cc index 514f8108..bbe46cc5 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -41,7 +41,7 @@ const char * memcached_lib_version(void) return LIBMEMCACHED_VERSION_STRING; } -static inline memcached_return_t memcached_version_textual(memcached_st *memc) +static inline memcached_return_t memcached_version_textual(Memcached *memc) { libmemcached_io_vector_st vector[]= { @@ -89,7 +89,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *memc) return errors_happened ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; } -static inline memcached_return_t memcached_version_binary(memcached_st *memc) +static inline memcached_return_t memcached_version_binary(Memcached *memc) { protocol_binary_request_version request= {}; @@ -202,8 +202,9 @@ void memcached_version_instance(org::libmemcached::Instance* instance) } } -memcached_return_t memcached_version(memcached_st *memc) +memcached_return_t memcached_version(memcached_st *shell) { + Memcached* memc= memcached2Memcached(shell); if (memc) { memcached_return_t rc; -- 2.30.2