From: Brian Aker Date: Sat, 7 Jul 2012 09:48:42 +0000 (-0700) Subject: First pass through turning instance into ++ X-Git-Tag: 1.0.10~5^2~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=674c7578fa870c3b57e81e765c355ce98434b310;p=awesomized%2Flibmemcached First pass through turning instance into ++ --- diff --git a/libmemcached-1.0/server.h b/libmemcached-1.0/server.h index f6430eca..dc650d2a 100644 --- a/libmemcached-1.0/server.h +++ b/libmemcached-1.0/server.h @@ -103,6 +103,9 @@ const char *memcached_server_name(const memcached_server_instance_st self); LIBMEMCACHED_API in_port_t memcached_server_port(const memcached_server_instance_st self); +LIBMEMCACHED_API +void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time); + LIBMEMCACHED_API const char *memcached_server_type(const memcached_server_instance_st ptr); diff --git a/libmemcached-1.0/struct/memcached.h b/libmemcached-1.0/struct/memcached.h index 138f9ef9..3de83a07 100644 --- a/libmemcached-1.0/struct/memcached.h +++ b/libmemcached-1.0/struct/memcached.h @@ -71,8 +71,13 @@ struct memcached_st { unsigned int version; } server_info; uint32_t number_of_hosts; - struct memcached_instance_st *servers; - struct memcached_instance_st *last_disconnected_server; +#ifdef __cplusplus + org::libmemcached::Instance* servers; + org::libmemcached::Instance* last_disconnected_server; +#else + void *servers; + void *last_disconnected_server; +#endif int32_t snd_timeout; int32_t rcv_timeout; uint32_t server_failure_limit; diff --git a/libmemcached-1.0/types.h b/libmemcached-1.0/types.h index 7ae29c2e..bb7e1a65 100644 --- a/libmemcached-1.0/types.h +++ b/libmemcached-1.0/types.h @@ -39,6 +39,9 @@ #pragma once #ifdef __cplusplus + +namespace org { namespace libmemcached { class Instance; } } + struct memcached_st; struct memcached_stat_st; struct memcached_analysis_st; @@ -49,7 +52,7 @@ struct memcached_error_t; // All of the flavors of memcache_server_st struct memcached_server_st; struct memcached_instance_st; -typedef const struct memcached_instance_st *memcached_server_instance_st; +typedef const org::libmemcached::Instance* memcached_server_instance_st; typedef struct memcached_server_st *memcached_server_list_st; struct memcached_callback_st; @@ -70,7 +73,7 @@ typedef struct memcached_error_t memcached_error_t; // All of the flavors of memcache_server_st typedef struct memcached_server_st memcached_server_st; -typedef const struct memcached_server_st *memcached_server_instance_st; +typedef const void *memcached_server_instance_st; typedef struct memcached_server_st *memcached_server_list_st; typedef struct memcached_callback_st memcached_callback_st; diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index adce3348..4196b668 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -37,7 +37,7 @@ #include -static void auto_response(memcached_server_write_instance_st instance, const bool reply, memcached_return_t& rc, uint64_t* value) +static void auto_response(org::libmemcached::Instance* instance, const bool reply, memcached_return_t& rc, uint64_t* value) { // If the message was successfully sent, then get the response, otherwise // fail. @@ -62,7 +62,7 @@ static void auto_response(memcached_server_write_instance_st instance, const boo } } -static memcached_return_t text_incr_decr(memcached_server_write_instance_st instance, +static memcached_return_t text_incr_decr(org::libmemcached::Instance* instance, const bool is_incr, const char *key, size_t key_length, const uint64_t offset, @@ -96,7 +96,7 @@ static memcached_return_t text_incr_decr(memcached_server_write_instance_st inst return memcached_vdo(instance, vector, 7, true); } -static memcached_return_t binary_incr_decr(memcached_server_write_instance_st instance, +static memcached_return_t binary_incr_decr(org::libmemcached::Instance* instance, protocol_binary_command cmd, const char *key, const size_t key_length, const uint64_t offset, @@ -179,7 +179,7 @@ static memcached_return_t increment_decrement_by_key(const protocol_binary_comma } uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key); bool reply= memcached_is_replying(instance->root); @@ -238,7 +238,7 @@ static memcached_return_t increment_decrement_with_initial_by_key(const protocol } uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key); bool reply= memcached_is_replying(instance->root); diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index fd096db2..e8bcf857 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -411,7 +411,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return (uint64_t) ptr->send_size; } - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0); if (instance) // If we have an instance we test, otherwise we just set and pray { @@ -445,7 +445,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, if (ptr->recv_size != -1) // If value is -1 then we are using the default return (uint64_t) ptr->recv_size; - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0); /** @note REFACTOR diff --git a/libmemcached/common.h b/libmemcached/common.h index 92f44de4..ecaf5906 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -82,25 +82,24 @@ #include "poll/poll.h" #endif - #ifdef __cplusplus extern "C" { #endif typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context); -LIBMEMCACHED_LOCAL -memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key); - -LIBMEMCACHED_LOCAL -memcached_return_t memcached_server_execute(memcached_st *ptr, - memcached_server_execute_fn callback, - void *context); #ifdef __cplusplus } // extern "C" #endif +#ifdef __cplusplus +org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key); +#endif + +memcached_return_t memcached_server_execute(memcached_st *ptr, + memcached_server_execute_fn callback, + void *context); /* These are private not to be installed headers */ #include #include @@ -164,7 +163,6 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, extern "C" { #endif -LIBMEMCACHED_LOCAL memcached_return_t run_distribution(memcached_st *ptr); #define memcached_server_response_increment(A) (A)->cursor_active++ @@ -175,10 +173,11 @@ memcached_return_t run_distribution(memcached_st *ptr); #define memcached_instance_response_decrement(A) (A)->cursor_active-- #define memcached_instance_response_reset(A) (A)->cursor_active=0 -bool memcached_purge(memcached_server_write_instance_st ptr); - -struct memcached_instance_st* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key); - #ifdef __cplusplus } #endif + +#ifdef __cplusplus +bool memcached_purge(org::libmemcached::Instance*); +org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key); +#endif diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index a8a2c5a4..647ea03b 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -46,7 +46,7 @@ #define SOCK_CLOEXEC 0 #endif -static memcached_return_t connect_poll(memcached_instance_st *server) +static memcached_return_t connect_poll(org::libmemcached::Instance* server) { struct pollfd fds[1]; fds[0].fd= server->fd; @@ -139,7 +139,7 @@ static memcached_return_t connect_poll(memcached_instance_st *server) return memcached_set_errno(*server, get_socket_errno(), MEMCACHED_AT); } -static memcached_return_t set_hostinfo(memcached_instance_st *server) +static memcached_return_t set_hostinfo(org::libmemcached::Instance* server) { assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET); if (server->address_info) @@ -150,8 +150,8 @@ static memcached_return_t set_hostinfo(memcached_instance_st *server) } char str_port[NI_MAXSERV]; - int length= snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port); - if (length >= NI_MAXSERV or length < 0) + int length= snprintf(str_port, NI_MAXSERV, "%u", uint32_t(server->port())); + if (length >= NI_MAXSERV or length <= 0) { return MEMCACHED_FAILURE; } @@ -203,7 +203,7 @@ static memcached_return_t set_hostinfo(memcached_instance_st *server) return MEMCACHED_SUCCESS; } -static inline void set_socket_nonblocking(memcached_instance_st *server) +static inline void set_socket_nonblocking(org::libmemcached::Instance* server) { #ifdef WIN32 u_long arg= 1; @@ -240,7 +240,7 @@ static inline void set_socket_nonblocking(memcached_instance_st *server) #endif } -static void set_socket_options(memcached_instance_st *server) +static void set_socket_options(org::libmemcached::Instance* server) { assert_msg(server->fd != INVALID_SOCKET, "invalid socket was passed to set_socket_options()"); @@ -349,7 +349,7 @@ static void set_socket_options(memcached_instance_st *server) set_socket_nonblocking(server); } -static memcached_return_t unix_socket_connect(memcached_instance_st *server) +static memcached_return_t unix_socket_connect(org::libmemcached::Instance* server) { #ifndef WIN32 WATCHPOINT_ASSERT(server->fd == INVALID_SOCKET); @@ -400,7 +400,7 @@ static memcached_return_t unix_socket_connect(memcached_instance_st *server) #endif } -static memcached_return_t network_connect(memcached_instance_st *server) +static memcached_return_t network_connect(org::libmemcached::Instance* server) { bool timeout_error_occured= false; @@ -572,7 +572,7 @@ static memcached_return_t network_connect(memcached_instance_st *server) Based on time/failure count fail the connect without trying. This prevents waiting in a state where we get caught spending cycles just waiting. */ -static memcached_return_t backoff_handling(memcached_server_write_instance_st server, bool& in_timeout) +static memcached_return_t backoff_handling(org::libmemcached::Instance* server, bool& in_timeout) { struct timeval curr_time; bool _gettime_success= (gettimeofday(&curr_time, NULL) == 0); @@ -639,7 +639,7 @@ static memcached_return_t backoff_handling(memcached_server_write_instance_st se return MEMCACHED_SUCCESS; } -static memcached_return_t _memcached_connect(memcached_server_write_instance_st server, const bool set_last_disconnected) +static memcached_return_t _memcached_connect(org::libmemcached::Instance* server, const bool set_last_disconnected) { if (server->fd != INVALID_SOCKET) { @@ -695,7 +695,7 @@ static memcached_return_t _memcached_connect(memcached_server_write_instance_st if (memcached_success(rc)) { - memcached_mark_server_as_clean(server); + server->mark_server_as_clean(); return rc; } else if (set_last_disconnected) @@ -717,7 +717,7 @@ static memcached_return_t _memcached_connect(memcached_server_write_instance_st if (in_timeout) { char buffer[1024]; - int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port)); + int snprintf_length= snprintf(buffer, sizeof(buffer), "%s:%d", server->hostname, int(server->port())); return memcached_set_error(*server, MEMCACHED_SERVER_TEMPORARILY_DISABLED, MEMCACHED_AT, buffer, snprintf_length); } } @@ -725,12 +725,12 @@ static memcached_return_t _memcached_connect(memcached_server_write_instance_st return rc; } -memcached_return_t memcached_connect_try(memcached_server_write_instance_st server) +memcached_return_t memcached_connect_try(org::libmemcached::Instance* server) { return _memcached_connect(server, false); } -memcached_return_t memcached_connect(memcached_server_write_instance_st server) +memcached_return_t memcached_connect(org::libmemcached::Instance* server) { return _memcached_connect(server, true); } diff --git a/libmemcached/connect.hpp b/libmemcached/connect.hpp index a37dbd76..96419513 100644 --- a/libmemcached/connect.hpp +++ b/libmemcached/connect.hpp @@ -37,6 +37,6 @@ #pragma once -memcached_return_t memcached_connect_try(memcached_server_write_instance_st ptr); -memcached_return_t memcached_connect(memcached_server_write_instance_st ptr); +memcached_return_t memcached_connect_try(org::libmemcached::Instance*); +memcached_return_t memcached_connect(org::libmemcached::Instance*); diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index a96ecbac..a7526dfc 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -44,7 +44,7 @@ memcached_return_t memcached_delete(memcached_st *memc, const char *key, size_t return memcached_delete_by_key(memc, key, key_length, key, key_length, expiration); } -static inline memcached_return_t ascii_delete(memcached_server_write_instance_st instance, +static inline memcached_return_t ascii_delete(org::libmemcached::Instance* instance, uint32_t , const char *key, const size_t key_length, @@ -65,7 +65,7 @@ static inline memcached_return_t ascii_delete(memcached_server_write_instance_st return memcached_vdo(instance, vector, 6, is_buffering ? false : true); } -static inline memcached_return_t binary_delete(memcached_server_write_instance_st instance, +static inline memcached_return_t binary_delete(org::libmemcached::Instance* instance, uint32_t server_key, const char *key, const size_t key_length, @@ -117,7 +117,7 @@ static inline memcached_return_t binary_delete(memcached_server_write_instance_s server_key= 0; } - memcached_server_write_instance_st replica= memcached_server_instance_fetch(instance->root, server_key); + org::libmemcached::Instance* replica= memcached_instance_fetch(instance->root, server_key); if (memcached_fatal(memcached_vdo(replica, vector, 4, should_flush))) { @@ -158,7 +158,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *memc, } uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key); bool is_buffering= memcached_is_buffering(instance->root); bool is_replying= memcached_is_replying(instance->root); diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 61a143b8..0d05ea6d 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -11,7 +11,7 @@ #include -memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, +memcached_return_t memcached_vdo(org::libmemcached::Instance* instance, libmemcached_io_vector_st vector[], const size_t count, const bool with_flush) @@ -23,7 +23,7 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, if (memcached_failed(rc= memcached_connect(instance))) { WATCHPOINT_ERROR(rc); - assert_msg(instance->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none."); + assert_msg(instance->error_messages, "memcached_connect() returned an error but the Instance showed none."); return rc; } diff --git a/libmemcached/do.hpp b/libmemcached/do.hpp index 560c1318..109c0ac1 100644 --- a/libmemcached/do.hpp +++ b/libmemcached/do.hpp @@ -37,7 +37,7 @@ #pragma once -memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr, +memcached_return_t memcached_vdo(org::libmemcached::Instance* ptr, libmemcached_io_vector_st vector[], const size_t count, const bool with_flush); diff --git a/libmemcached/dump.cc b/libmemcached/dump.cc index 05b4e5d6..618a63cd 100644 --- a/libmemcached/dump.cc +++ b/libmemcached/dump.cc @@ -68,7 +68,7 @@ static memcached_return_t ascii_dump(memcached_st *memc, memcached_dump_fn *call // Send message to all servers for (uint32_t server_key= 0; server_key < memcached_server_count(memc); server_key++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key); memcached_return_t vdo_rc; if (memcached_success((vdo_rc= memcached_vdo(instance, vector, 3, true)))) @@ -82,7 +82,7 @@ static memcached_return_t ascii_dump(memcached_st *memc, memcached_dump_fn *call } // Collect the returned items - memcached_server_write_instance_st instance; + org::libmemcached::Instance* instance; while ((instance= memcached_io_get_readable_server(memc))) { memcached_return_t response_rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 62616b30..38c568c9 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(memcached_instance_st& server, memcached_st& memc) +static void _set(org::libmemcached::Instance& server, memcached_st& memc) { if (server.error_messages and server.error_messages->query_id != server.root->query_id) { @@ -204,10 +204,10 @@ memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc return memcached_set_error(memc, rc, at, tmp); } -memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, const char *str, size_t length) +memcached_return_t memcached_set_error(org::libmemcached::Instance& self, memcached_return_t rc, const char *at, const char *str, size_t length) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a Instance"); memcached_string_t tmp= { str, length }; return memcached_set_error(self, rc, at, tmp); @@ -240,7 +240,7 @@ memcached_return_t memcached_set_parser_error(memcached_st& memc, return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length); } -static inline size_t append_host_to_string(memcached_instance_st& self, char* buffer, const size_t buffer_length) +static inline size_t append_host_to_string(org::libmemcached::Instance& self, char* buffer, const size_t buffer_length) { size_t size= 0; switch (self.type) @@ -248,7 +248,7 @@ static inline size_t append_host_to_string(memcached_instance_st& self, char* bu case MEMCACHED_CONNECTION_TCP: case MEMCACHED_CONNECTION_UDP: size+= snprintf(buffer, buffer_length, " host: %s:%d", - self.hostname, int(self.port)); + self.hostname, int(self.port())); break; case MEMCACHED_CONNECTION_UNIX_SOCKET: @@ -260,10 +260,10 @@ static inline size_t append_host_to_string(memcached_instance_st& self, char* bu return size; } -memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at, memcached_string_t& str) +memcached_return_t memcached_set_error(org::libmemcached::Instance& self, memcached_return_t rc, const char *at, memcached_string_t& str) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a org::libmemcached::Instance"); if (memcached_fatal(rc) == false) { return rc; @@ -297,9 +297,9 @@ memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_re return rc; } -memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_return_t rc, const char *at) +memcached_return_t memcached_set_error(org::libmemcached::Instance& self, memcached_return_t rc, const char *at) { - assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_instance_st"); + assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a org::libmemcached::Instance"); if (memcached_fatal(rc) == false) { return rc; @@ -340,7 +340,7 @@ memcached_return_t memcached_set_errno(memcached_st& self, int local_errno, cons return memcached_set_errno(self, local_errno, at, tmp); } -memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, const char *str, size_t length) +memcached_return_t memcached_set_errno(org::libmemcached::Instance& self, int local_errno, const char *at, const char *str, size_t length) { memcached_string_t tmp= { str, length }; return memcached_set_errno(self, local_errno, at, tmp); @@ -372,7 +372,7 @@ memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, cons return rc; } -memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at, memcached_string_t& str) +memcached_return_t memcached_set_errno(org::libmemcached::Instance& self, int local_errno, const char *at, memcached_string_t& str) { if (local_errno == 0) { @@ -402,7 +402,7 @@ memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_er return rc; } -memcached_return_t memcached_set_errno(memcached_instance_st& self, int local_errno, const char *at) +memcached_return_t memcached_set_errno(org::libmemcached::Instance& self, int local_errno, const char *at) { if (local_errno == 0) { @@ -456,7 +456,7 @@ void memcached_error_print(const memcached_st *self) for (uint32_t x= 0; x < memcached_server_count(self); x++) { - memcached_server_instance_st instance= memcached_server_instance_by_position(self, x); + org::libmemcached::Instance* instance= memcached_instance_by_position(self, x); _error_print(instance->error_messages); } @@ -478,7 +478,7 @@ void memcached_error_free(memcached_st& self) self.error_messages= NULL; } -void memcached_error_free(memcached_instance_st& self) +void memcached_error_free(org::libmemcached::Instance& self) { _error_free(self.error_messages); self.error_messages= NULL; @@ -522,7 +522,7 @@ bool memcached_has_current_error(memcached_st &memc) return false; } -bool memcached_has_current_error(memcached_instance_st& server) +bool memcached_has_current_error(org::libmemcached::Instance& server) { return memcached_has_current_error(*(server.root)); } @@ -578,7 +578,7 @@ const char *memcached_server_error(const memcached_server_instance_st server) } -memcached_error_t *memcached_error_copy(const memcached_instance_st& server) +memcached_error_t *memcached_error_copy(const org::libmemcached::Instance& server) { if (server.error_messages == NULL) { @@ -607,7 +607,7 @@ memcached_return_t memcached_server_error_return(memcached_server_instance_st pt return MEMCACHED_SUCCESS; } -memcached_return_t memcached_instance_error_return(memcached_instance_st* instance) +memcached_return_t memcached_instance_error_return(org::libmemcached::Instance* instance) { if (instance == NULL) { diff --git a/libmemcached/error.hpp b/libmemcached/error.hpp index 26c56367..5b82d13a 100644 --- a/libmemcached/error.hpp +++ b/libmemcached/error.hpp @@ -45,64 +45,46 @@ #define TOSTRING(x) STRINGIFY(x) #define MEMCACHED_AT __FILE__ ":" TOSTRING(__LINE__) -LIBMEMCACHED_LOCAL memcached_return_t memcached_set_parser_error(memcached_st& memc, const char *at, const char *format, ...); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at); +memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at); +memcached_return_t memcached_set_error(org::libmemcached::Instance&, memcached_return_t rc, const char *at); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at, const char *str, size_t length); +memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at, const char *str, size_t length); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, const char *str, size_t length); +memcached_return_t memcached_set_error(org::libmemcached::Instance&, memcached_return_t rc, const char *at, const char *str, size_t length); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc, const char *at, memcached_string_t& str); +memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc, const char *at, memcached_string_t& str); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_error(memcached_instance_st&, memcached_return_t rc, const char *at, memcached_string_t& str); +memcached_return_t memcached_set_error(org::libmemcached::Instance&, memcached_return_t rc, const char *at, memcached_string_t& str); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, memcached_string_t& str); +memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, memcached_string_t& str); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, memcached_string_t& str); +memcached_return_t memcached_set_errno(org::libmemcached::Instance&, int local_errno, const char *at, memcached_string_t& str); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, const char *str, size_t length); +memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at, const char *str, size_t length); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at, const char *str, size_t length); +memcached_return_t memcached_set_errno(org::libmemcached::Instance&, int local_errno, const char *at, const char *str, size_t length); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at); +memcached_return_t memcached_set_errno(memcached_st& memc, int local_errno, const char *at); -LIBMEMCACHED_LOCAL - memcached_return_t memcached_set_errno(memcached_instance_st&, int local_errno, const char *at); +memcached_return_t memcached_set_errno(org::libmemcached::Instance&, int local_errno, const char *at); -LIBMEMCACHED_LOCAL bool memcached_has_current_error(memcached_st&); -LIBMEMCACHED_LOCAL -bool memcached_has_current_error(memcached_instance_st&); +bool memcached_has_current_error(org::libmemcached::Instance&); -LIBMEMCACHED_LOCAL void memcached_error_free(memcached_st&); -void memcached_error_free(memcached_server_st& self); +void memcached_error_free(memcached_server_st&); -LIBMEMCACHED_LOCAL -void memcached_error_free(memcached_instance_st&); +void memcached_error_free(org::libmemcached::Instance& self); -LIBMEMCACHED_LOCAL -memcached_error_t *memcached_error_copy(const memcached_instance_st&); +memcached_error_t *memcached_error_copy(const org::libmemcached::Instance&); -memcached_return_t memcached_instance_error_return(memcached_instance_st*); +memcached_return_t memcached_instance_error_return(org::libmemcached::Instance*); #endif diff --git a/libmemcached/exist.cc b/libmemcached/exist.cc index 58408fd7..56c1efce 100644 --- a/libmemcached/exist.cc +++ b/libmemcached/exist.cc @@ -36,7 +36,7 @@ #include -static memcached_return_t ascii_exist(memcached_st *memc, memcached_server_write_instance_st instance, const char *key, size_t key_length) +static memcached_return_t ascii_exist(memcached_st *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, memcached_server_write return rc; } -static memcached_return_t binary_exist(memcached_st *memc, memcached_server_write_instance_st instance, const char *key, size_t key_length) +static memcached_return_t binary_exist(memcached_st *memc, org::libmemcached::Instance* instance, const char *key, size_t key_length) { protocol_binary_request_set request= {}; size_t send_length= sizeof(request.bytes); @@ -143,7 +143,7 @@ memcached_return_t memcached_exist_by_key(memcached_st *memc, } uint32_t server_key= memcached_generate_hash_with_redistribution(memc, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, server_key); if (memcached_is_binary(memc)) { diff --git a/libmemcached/fetch.cc b/libmemcached/fetch.cc index 2fd0dc51..70e5bf75 100644 --- a/libmemcached/fetch.cc +++ b/libmemcached/fetch.cc @@ -191,7 +191,7 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, } *error= MEMCACHED_MAXIMUM_RETURN; // We use this to see if we ever go into the loop - memcached_instance_st *server; + org::libmemcached::Instance *server; while ((server= memcached_io_get_readable_server(ptr))) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index ef790922..1e1533dd 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -52,7 +52,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); initialize_binary_request(instance, request.message.header); if (reply) @@ -84,7 +84,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); if (memcached_instance_response_count(instance) > 0) { @@ -115,7 +115,7 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, memcached_return_t rc= MEMCACHED_SUCCESS; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); libmemcached_io_vector_st vector[]= { diff --git a/libmemcached/flush_buffers.cc b/libmemcached/flush_buffers.cc index 58260fc1..af6942b4 100644 --- a/libmemcached/flush_buffers.cc +++ b/libmemcached/flush_buffers.cc @@ -43,8 +43,7 @@ memcached_return_t memcached_flush_buffers(memcached_st *memc) for (uint32_t x= 0; x < memcached_server_count(memc); ++x) { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(memc, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); if (instance->write_buffer_offset != 0) { diff --git a/libmemcached/get.cc b/libmemcached/get.cc index cc6af2d8..73802e20 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -244,7 +244,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, */ for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); if (memcached_instance_response_count(instance)) { @@ -282,7 +282,6 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, size_t hosts_connected= 0; for (uint32_t x= 0; x < number_of_keys; x++) { - memcached_server_write_instance_st instance; uint32_t server_key; if (is_group_key_set) @@ -294,7 +293,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]); } - instance= memcached_server_instance_fetch(ptr, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); libmemcached_io_vector_st vector[]= { @@ -355,8 +354,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, bool success_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); if (memcached_instance_response_count(instance)) { @@ -480,7 +478,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]); } - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); if (memcached_instance_response_count(instance) == 0) { @@ -553,7 +551,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, for (uint32_t x= 0; x < memcached_server_count(ptr); ++x) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); initialize_binary_request(instance, request.message.header); if (memcached_instance_response_count(instance)) @@ -624,7 +622,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, continue; } - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server); if (memcached_instance_response_count(instance) == 0) { diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 898bff9d..dbfba007 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -52,7 +52,7 @@ static int compare_servers(const void *p1, const void *p2) if (return_value == 0) { - return_value= (int) (a->port - b->port); + return_value= int(a->port() - b->port()); } return return_value; @@ -62,10 +62,9 @@ static void sort_hosts(memcached_st *ptr) { if (memcached_server_count(ptr)) { - memcached_server_write_instance_st instance; - qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(memcached_instance_st), compare_servers); - instance= memcached_server_instance_fetch(ptr, 0); + qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(org::libmemcached::Instance), compare_servers); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0); instance->number_of_hosts= memcached_server_count(ptr); } } @@ -143,7 +142,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) return memcached_set_errno(*ptr, errno, MEMCACHED_AT); } - memcached_instance_st *list= memcached_instance_list(ptr); + org::libmemcached::Instance* list= memcached_instance_list(ptr); /* count live servers (those without a retry delay set) */ bool is_auto_ejecting= _is_auto_eject_host(ptr); @@ -174,7 +173,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER); - if (not live_servers) + if (live_servers == 0) { return MEMCACHED_SUCCESS; } @@ -222,7 +221,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) { printf("ketama_weighted:%s|%d|%llu|%u\n", list[host_index].hostname, - list[host_index].port, + list[host_index].port(), (unsigned long long)list[host_index].weight, pointer_per_server); } @@ -243,7 +242,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) sort_host_length= snprintf(sort_host, sizeof(sort_host), "/%s:%u-%u", list[host_index].hostname, - (uint32_t)list[host_index].port, + (uint32_t)list[host_index].port(), pointer_index); if (size_t(sort_host_length) >= sizeof(sort_host) or sort_host_length < 0) @@ -283,7 +282,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) char sort_host[MEMCACHED_NI_MAXHOST +1 +MEMCACHED_NI_MAXSERV +1 +MEMCACHED_NI_MAXSERV]= ""; int sort_host_length; - if (list[host_index].port == MEMCACHED_DEFAULT_PORT) + if (list[host_index].port() == MEMCACHED_DEFAULT_PORT) { sort_host_length= snprintf(sort_host, sizeof(sort_host), "%s-%u", @@ -295,7 +294,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) sort_host_length= snprintf(sort_host, sizeof(sort_host), "%s:%u-%u", list[host_index].hostname, - (uint32_t)list[host_index].port, + (uint32_t)list[host_index].port(), pointer_index - 1); } @@ -351,7 +350,7 @@ static memcached_return_t server_add(memcached_st *ptr, { assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); - memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), memcached_instance_st); + org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (ptr->number_of_hosts + 1), org::libmemcached::Instance); if (new_host_list == NULL) { @@ -361,7 +360,7 @@ static memcached_return_t server_add(memcached_st *ptr, memcached_instance_set(ptr, new_host_list); /* TODO: Check return type */ - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr)); if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL) { @@ -376,7 +375,7 @@ static memcached_return_t server_add(memcached_st *ptr, ptr->number_of_hosts++; // @note we place the count in the bottom of the server list - instance= memcached_server_instance_fetch(ptr, 0); + instance= memcached_instance_fetch(ptr, 0); memcached_instance_set_count(instance, memcached_server_count(ptr)); return run_distribution(ptr); @@ -392,7 +391,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv uint32_t count= memcached_server_list_count(list); - memcached_instance_st *new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), memcached_instance_st); + org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (count + memcached_server_count(ptr)), org::libmemcached::Instance); if (new_host_list == NULL) { @@ -403,12 +402,10 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv for (uint32_t x= 0; x < count; x++) { - memcached_server_write_instance_st instance; - WATCHPOINT_ASSERT(list[x].hostname[0] != 0); // We have extended the array, and now we will find it, and use it. - instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr)); WATCHPOINT_ASSERT(instance); memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; @@ -429,22 +426,21 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv // Provides backwards compatibility with server list. { - memcached_server_write_instance_st instance; - instance= memcached_server_instance_fetch(ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0); instance->number_of_hosts= memcached_server_count(ptr); } return run_distribution(ptr); } -memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st* list, uint32_t number_of_hosts) +memcached_return_t memcached_instance_push(memcached_st *ptr, const struct org::libmemcached::Instance* list, uint32_t number_of_hosts) { if (list == NULL) { return MEMCACHED_SUCCESS; } - memcached_instance_st* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (number_of_hosts +memcached_server_count(ptr)), memcached_instance_st); + org::libmemcached::Instance* new_host_list= libmemcached_xrealloc(ptr, memcached_instance_list(ptr), (number_of_hosts +memcached_server_count(ptr)), org::libmemcached::Instance); if (new_host_list == NULL) { @@ -455,18 +451,17 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memca for (uint32_t x= 0; x < number_of_hosts; x++) { - memcached_server_write_instance_st instance; WATCHPOINT_ASSERT(list[x].hostname[0] != 0); // We have extended the array, and now we will find it, and use it. - instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, memcached_server_count(ptr)); 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) + list[x].port(), list[x].weight, list[x].type) == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } @@ -481,8 +476,7 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memca // Provides backwards compatibility with server list. { - memcached_server_write_instance_st instance; - instance= memcached_server_instance_fetch(ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0); instance->number_of_hosts= memcached_server_count(ptr); } diff --git a/libmemcached/instance.cc b/libmemcached/instance.cc index 0662b8f6..e7bb3794 100644 --- a/libmemcached/instance.cc +++ b/libmemcached/instance.cc @@ -35,12 +35,9 @@ * */ -/* - This is a partial implementation for fetching/creating memcached_instance_st objects. -*/ #include -static inline void _server_init(memcached_instance_st *self, memcached_st *root, +static inline void _server_init(org::libmemcached::Instance* self, memcached_st *root, const memcached_string_t& hostname, in_port_t port, uint32_t weight, memcached_connection_t type) @@ -49,7 +46,7 @@ static inline void _server_init(memcached_instance_st *self, memcached_st *root, self->options.is_dead= false; self->number_of_hosts= 0; self->cursor_active= 0; - self->port= port; + self->port_= port; self->fd= INVALID_SOCKET; self->io_bytes_sent= 0; self->request_id= 0; @@ -89,11 +86,11 @@ static inline void _server_init(memcached_instance_st *self, memcached_st *root, self->hostname[hostname.size]= 0; } -static memcached_instance_st *_server_create(memcached_instance_st *self, const memcached_st *memc) +static org::libmemcached::Instance* _server_create(org::libmemcached::Instance* self, const memcached_st *memc) { if (self == NULL) { - self= libmemcached_xmalloc(memc, struct memcached_instance_st); + self= libmemcached_xmalloc(memc, org::libmemcached::Instance); if (self == NULL) { @@ -112,12 +109,12 @@ static memcached_instance_st *_server_create(memcached_instance_st *self, const return self; } -memcached_instance_st *__instance_create_with(memcached_st *memc, - memcached_instance_st* self, - const memcached_string_t& hostname, - const in_port_t port, - uint32_t weight, - const memcached_connection_t type) +org::libmemcached::Instance* __instance_create_with(memcached_st *memc, + org::libmemcached::Instance* self, + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type) { if (memcached_is_valid_servername(hostname) == false) { @@ -148,7 +145,7 @@ memcached_instance_st *__instance_create_with(memcached_st *memc, return self; } -void __instance_free(memcached_instance_st *self) +void __instance_free(org::libmemcached::Instance* self) { memcached_quit_server(self, false); @@ -171,26 +168,20 @@ void __instance_free(memcached_instance_st *self) } } -void memcached_instance_free(memcached_instance_st *self) +void memcached_instance_free(org::libmemcached::Instance* self) { if (self == NULL) { return; } - if (memcached_instance_count(self)) - { - memcached_instance_list_free(self, memcached_instance_count(self)); - return; - } - __instance_free(self); } /* If we do not have a valid object to clone from, we toss an error. */ -memcached_server_st *memcached_instance_2_server(memcached_instance_st *source) +memcached_server_st *memcached_instance_2_server(org::libmemcached::Instance* source) { /* We just do a normal create if source is missing */ if (source == NULL) @@ -201,7 +192,7 @@ memcached_server_st *memcached_instance_2_server(memcached_instance_st *source) memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; return __server_create_with(source->root, NULL, hostname, - source->port, source->weight, + source->port(), source->weight, source->type); } @@ -220,8 +211,7 @@ memcached_return_t memcached_server_cursor(const memcached_st *ptr, size_t errors= 0; for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++) { - memcached_server_instance_st instance= - memcached_server_instance_by_position(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_by_position(ptr, x); for (uint32_t y= 0; y < number_of_callbacks; y++) { @@ -250,7 +240,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, bool some_errors= false;; for (uint32_t x= 0; x < memcached_instance_list_count(ptr); x++) { - memcached_instance_st* instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); memcached_return_t rc= (*callback)(ptr, instance, context); if (rc == MEMCACHED_INVALID_ARGUMENTS) @@ -273,7 +263,7 @@ memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, memcached_return_t *error) { memcached_return_t unused; - if (not error) + if (error == NULL) { error= &unused; } @@ -293,13 +283,13 @@ memcached_server_instance_st memcached_server_by_key(memcached_st *ptr, } uint32_t server_key= memcached_generate_hash(ptr, key, key_length); - return memcached_server_instance_by_position(ptr, server_key); + return memcached_instance_by_position(ptr, server_key); } /* If we do not have a valid object to clone from, we toss an error. */ -static memcached_instance_st *memcached_instance_clone(memcached_instance_st *source) +static org::libmemcached::Instance* memcached_instance_clone(org::libmemcached::Instance* source) { /* We just do a normal create if source is missing */ if (source == NULL) @@ -311,11 +301,11 @@ static memcached_instance_st *memcached_instance_clone(memcached_instance_st *so return __instance_create_with(source->root, NULL, hostname, - source->port, source->weight, + source->port(), source->weight, source->type); } -void set_last_disconnected_host(memcached_server_write_instance_st self) +void set_last_disconnected_host(org::libmemcached::Instance* self) { assert(self->root); if (self->root == NULL) @@ -323,7 +313,8 @@ void set_last_disconnected_host(memcached_server_write_instance_st self) return; } - if (self->root->last_disconnected_server and self->root->last_disconnected_server->version == self->version) + if (memcached_server_get_last_disconnect(self->root) and + memcached_server_get_last_disconnect(self->root)->version == self->version) { return; } @@ -331,9 +322,9 @@ void set_last_disconnected_host(memcached_server_write_instance_st self) // const_cast memcached_st *root= (memcached_st *)self->root; - memcached_instance_free(root->last_disconnected_server); + memcached_instance_free((org::libmemcached::Instance*)(root->last_disconnected_server)); root->last_disconnected_server= memcached_instance_clone(self); - root->last_disconnected_server->version= self->version; + ((org::libmemcached::Instance*)memcached_server_get_last_disconnect(root))->version= self->version; } memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self) @@ -344,10 +335,10 @@ memcached_server_instance_st memcached_server_get_last_disconnect(const memcache return 0; } - return self->last_disconnected_server; + return (memcached_server_instance_st)self->last_disconnected_server; } -uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count) +uint32_t memcached_instance_set_count(org::libmemcached::Instance* servers, uint32_t count) { WATCHPOINT_ASSERT(servers); if (servers == NULL) @@ -375,10 +366,19 @@ in_port_t memcached_instance_port(const memcached_server_instance_st self) return 0; } - return self->port; + return self->port(); +} + +void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time) +{ + WATCHPOINT_ASSERT(self); + if (self) + { + ((org::libmemcached::Instance*)self)->next_retry= absolute_time; + } } -uint32_t memcached_instance_response_count(const memcached_instance_st* self) +uint32_t memcached_instance_response_count(const org::libmemcached::Instance* self) { WATCHPOINT_ASSERT(self); if (self == NULL) diff --git a/libmemcached/instance.h b/libmemcached/instance.h index 16d509f0..1c81da44 100644 --- a/libmemcached/instance.h +++ b/libmemcached/instance.h @@ -54,7 +54,28 @@ #define MEMCACHED_NI_MAXSERV 32 #endif -struct memcached_instance_st { +#ifdef __cplusplus + +namespace org { +namespace libmemcached { + +struct Instance { + in_port_t port() const + { + return port_; + } + + void port(in_port_t arg) + { + port_= arg; + } + + inline void mark_server_as_clean() + { + server_failure_counter= 0; + next_retry= 0; + } + struct { bool is_allocated:1; bool is_initialized:1; @@ -63,7 +84,7 @@ struct memcached_instance_st { } options; uint32_t number_of_hosts; uint32_t cursor_active; - in_port_t port; + in_port_t port_; memcached_socket_t fd; uint32_t io_bytes_sent; /* # bytes sent since last read */ uint32_t request_id; @@ -96,3 +117,8 @@ struct memcached_instance_st { char write_buffer[MEMCACHED_MAX_BUFFER]; char hostname[MEMCACHED_NI_MAXHOST]; }; + +} // namespace libmemcached +} // namespace org + +#endif diff --git a/libmemcached/instance.hpp b/libmemcached/instance.hpp index 9ab3622a..a69b8ea3 100644 --- a/libmemcached/instance.hpp +++ b/libmemcached/instance.hpp @@ -38,24 +38,25 @@ #pragma once -struct memcached_instance_st *__instance_create_with(memcached_st *memc, - struct memcached_instance_st* self, - const memcached_string_t& hostname, - const in_port_t port, - uint32_t weight, - const memcached_connection_t type); -const char *memcached_instance_name(const memcached_server_instance_st self); +org::libmemcached::Instance* __instance_create_with(memcached_st *memc, + org::libmemcached::Instance* self, + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type); -in_port_t memcached_instance_port(const memcached_server_instance_st self); +const char *memcached_instance_name(const org::libmemcached::Instance* self); -memcached_return_t memcached_instance_push(memcached_st *ptr, const struct memcached_instance_st*, uint32_t); +in_port_t memcached_instance_port(const org::libmemcached::Instance* self); -memcached_server_st *memcached_instance_2_server(struct memcached_instance_st*); +memcached_return_t memcached_instance_push(memcached_st *ptr, const org::libmemcached::Instance*, uint32_t); + +memcached_server_st *memcached_instance_2_server(org::libmemcached::Instance* source); uint32_t memcached_instance_count(const memcached_st* self); -uint32_t memcached_instance_response_count(const memcached_instance_st* self); +uint32_t memcached_instance_response_count(const org::libmemcached::Instance* self); -uint32_t memcached_instance_set_count(memcached_instance_st *servers, uint32_t count); +uint32_t memcached_instance_set_count(org::libmemcached::Instance *servers, uint32_t count); -void __instance_free(struct memcached_instance_st *); +void __instance_free(org::libmemcached::Instance *); diff --git a/libmemcached/io.cc b/libmemcached/io.cc index d2e40043..837959da 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -39,7 +39,7 @@ #include -void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header& header) +void initialize_binary_request(org::libmemcached::Instance* server, protocol_binary_request_header& header) { server->request_id++; header.request.magic= PROTOCOL_BINARY_REQ; @@ -57,7 +57,7 @@ enum memc_read_or_write { * * @param ptr the server to pack */ -static bool repack_input_buffer(memcached_server_write_instance_st ptr) +static bool repack_input_buffer(org::libmemcached::Instance* ptr) { if (ptr->read_ptr != ptr->read_buffer) { @@ -130,7 +130,7 @@ static bool repack_input_buffer(memcached_server_write_instance_st ptr) * @param ptr the server to star processing iput messages for * @return true if we processed anything, false otherwise */ -static bool process_input_buffer(memcached_server_write_instance_st ptr) +static bool process_input_buffer(org::libmemcached::Instance* ptr) { /* ** We might be able to process some of the response messages if we @@ -172,7 +172,7 @@ static bool process_input_buffer(memcached_server_write_instance_st ptr) return false; } -static memcached_return_t io_wait(memcached_server_write_instance_st ptr, +static memcached_return_t io_wait(org::libmemcached::Instance* ptr, const memc_read_or_write read_or_write) { /* @@ -294,7 +294,7 @@ static memcached_return_t io_wait(memcached_server_write_instance_st ptr, memcached_literal_param("number of attempts to call io_wait() failed")); } -static bool io_flush(memcached_server_write_instance_st ptr, +static bool io_flush(org::libmemcached::Instance* ptr, const bool with_flush, memcached_return_t& error) { @@ -396,12 +396,12 @@ static bool io_flush(memcached_server_write_instance_st ptr, return true; } -memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr) +memcached_return_t memcached_io_wait_for_write(org::libmemcached::Instance* ptr) { return io_wait(ptr, MEM_WRITE); } -static memcached_return_t _io_fill(memcached_server_write_instance_st ptr) +static memcached_return_t _io_fill(org::libmemcached::Instance* ptr) { ssize_t data_read; do @@ -477,11 +477,11 @@ static memcached_return_t _io_fill(memcached_server_write_instance_st ptr) return MEMCACHED_SUCCESS; } -memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, +memcached_return_t memcached_io_read(org::libmemcached::Instance* ptr, void *buffer, size_t length, ssize_t& nread) { assert(memcached_is_udp(ptr->root) == false); - assert_msg(ptr, "Programmer error, memcached_io_read() recieved an invalid memcached_server_write_instance_st"); // Programmer error + assert_msg(ptr, "Programmer error, memcached_io_read() recieved an invalid Instance"); // Programmer error char *buffer_ptr= static_cast(buffer); if (ptr->fd == INVALID_SOCKET) @@ -529,9 +529,9 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, return MEMCACHED_SUCCESS; } -memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr) +memcached_return_t memcached_io_slurp(org::libmemcached::Instance* ptr) { - assert_msg(ptr, "Programmer error, invalid memcached_server_write_instance_st"); + assert_msg(ptr, "Programmer error, invalid Instance"); assert(memcached_is_udp(ptr->root) == false); if (ptr->fd == INVALID_SOCKET) @@ -586,7 +586,7 @@ memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr) return MEMCACHED_CONNECTION_FAILURE; } -static bool _io_write(memcached_server_write_instance_st ptr, +static bool _io_write(org::libmemcached::Instance* ptr, const void *buffer, size_t length, bool with_flush, size_t& written) { @@ -639,13 +639,13 @@ static bool _io_write(memcached_server_write_instance_st ptr, return true; } -bool memcached_io_write(memcached_server_write_instance_st ptr) +bool memcached_io_write(org::libmemcached::Instance* ptr) { size_t written; return _io_write(ptr, NULL, 0, true, written); } -ssize_t memcached_io_write(memcached_server_write_instance_st ptr, +ssize_t memcached_io_write(org::libmemcached::Instance* ptr, const void *buffer, const size_t length, const bool with_flush) { size_t written; @@ -658,9 +658,9 @@ ssize_t memcached_io_write(memcached_server_write_instance_st ptr, return ssize_t(written); } -bool memcached_io_writev(memcached_server_write_instance_st ptr, - libmemcached_io_vector_st vector[], - const size_t number_of, const bool with_flush) +bool memcached_io_writev(org::libmemcached::Instance* ptr, + libmemcached_io_vector_st vector[], + const size_t number_of, const bool with_flush) { ssize_t complete_total= 0; ssize_t total= 0; @@ -691,7 +691,7 @@ bool memcached_io_writev(memcached_server_write_instance_st ptr, } -void memcached_io_close(memcached_server_write_instance_st ptr) +void memcached_io_close(org::libmemcached::Instance* ptr) { if (ptr->fd == INVALID_SOCKET) { @@ -714,7 +714,7 @@ void memcached_io_close(memcached_server_write_instance_st ptr) ptr->fd= INVALID_SOCKET; } -memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc) +org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc) { #define MAX_SERVERS_TO_POLL 100 struct pollfd fds[MAX_SERVERS_TO_POLL]; @@ -722,7 +722,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st for (uint32_t x= 0; x < memcached_server_count(memc) and host_index < MAX_SERVERS_TO_POLL; ++x) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); if (instance->read_buffer_length > 0) /* I have data in the buffer */ { @@ -743,7 +743,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st /* We have 0 or 1 server with pending events.. */ for (uint32_t x= 0; x< memcached_server_count(memc); ++x) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); if (memcached_instance_response_count(instance) > 0) { @@ -770,7 +770,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st { for (uint32_t y= 0; y < memcached_server_count(memc); ++y) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc, y); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, y); if (instance->fd == fds[x].fd) { @@ -787,7 +787,7 @@ memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st /* Eventually we will just kill off the server with the problem. */ -void memcached_io_reset(memcached_server_write_instance_st ptr) +void memcached_io_reset(org::libmemcached::Instance* ptr) { memcached_quit_server(ptr, true); } @@ -796,7 +796,7 @@ void memcached_io_reset(memcached_server_write_instance_st ptr) * Read a given number of bytes from the server and place it into a specific * buffer. Reset the IO channel on this server if an error occurs. */ -memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, +memcached_return_t memcached_safe_read(org::libmemcached::Instance* ptr, void *dta, const size_t size) { @@ -821,7 +821,7 @@ memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, return MEMCACHED_SUCCESS; } -memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr, +memcached_return_t memcached_io_readline(org::libmemcached::Instance* ptr, char *buffer_ptr, size_t size, size_t& total_nr) diff --git a/libmemcached/io.hpp b/libmemcached/io.hpp index bff6b83d..5625ce94 100644 --- a/libmemcached/io.hpp +++ b/libmemcached/io.hpp @@ -38,37 +38,37 @@ #pragma once -void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header&); +void initialize_binary_request(org::libmemcached::Instance* server, protocol_binary_request_header&); -bool memcached_io_write(memcached_server_write_instance_st ptr); +bool memcached_io_write(org::libmemcached::Instance* ptr); -ssize_t memcached_io_write(memcached_server_write_instance_st ptr, +ssize_t memcached_io_write(org::libmemcached::Instance* ptr, const void *buffer, size_t length, bool with_flush); -bool memcached_io_writev(memcached_server_write_instance_st ptr, +bool memcached_io_writev(org::libmemcached::Instance* ptr, libmemcached_io_vector_st vector[], const size_t number_of, const bool with_flush); -memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr); +memcached_return_t memcached_io_wait_for_write(org::libmemcached::Instance* ptr); -void memcached_io_reset(memcached_server_write_instance_st ptr); +void memcached_io_reset(org::libmemcached::Instance* ptr); -memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, +memcached_return_t memcached_io_read(org::libmemcached::Instance* ptr, void *buffer, size_t length, ssize_t& nread); /* Read a line (terminated by '\n') into the buffer */ -memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr, +memcached_return_t memcached_io_readline(org::libmemcached::Instance* ptr, char *buffer_ptr, size_t size, size_t& total); -void memcached_io_close(memcached_server_write_instance_st ptr); +void memcached_io_close(org::libmemcached::Instance* ptr); /* Read n bytes of data from the server and store them in dta */ -memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, +memcached_return_t memcached_safe_read(org::libmemcached::Instance* ptr, void *dta, const size_t size); -memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc); +org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc); -memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr); +memcached_return_t memcached_io_slurp(org::libmemcached::Instance* ptr); diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 0574cc6c..5f57c515 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -133,7 +133,7 @@ static void __memcached_free(memcached_st *ptr, bool release_st) memcached_virtual_bucket_free(ptr); - memcached_instance_free(ptr->last_disconnected_server); + memcached_instance_free((org::libmemcached::Instance*)ptr->last_disconnected_server); if (ptr->on_cleanup) { @@ -279,7 +279,7 @@ void memcached_servers_reset(memcached_st *self) memcached_instance_set(self, NULL); self->number_of_hosts= 0; - memcached_instance_free(self->last_disconnected_server); + memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server); self->last_disconnected_server= NULL; } } @@ -288,7 +288,7 @@ void memcached_reset_last_disconnected_server(memcached_st *self) { if (self) { - memcached_instance_free(self->last_disconnected_server); + memcached_instance_free((org::libmemcached::Instance*)self->last_disconnected_server); self->last_disconnected_server= NULL; } } @@ -421,10 +421,10 @@ void *memcached_set_user_data(memcached_st *ptr, void *data) memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source) { - return memcached_instance_push(destination, source->servers, source->number_of_hosts); + return memcached_instance_push(destination, (org::libmemcached::Instance*)source->servers, source->number_of_hosts); } -memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) +org::libmemcached::Instance* memcached_instance_fetch(memcached_st *ptr, uint32_t server_key) { if (ptr == NULL) { @@ -444,6 +444,16 @@ memcached_server_instance_st memcached_server_instance_by_position(const memcach return &ptr->servers[server_key]; } +org::libmemcached::Instance* memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key) +{ + if (ptr == NULL) + { + return NULL; + } + + return &ptr->servers[server_key]; +} + uint64_t memcached_query_id(const memcached_st *self) { if (self == NULL) @@ -453,3 +463,14 @@ uint64_t memcached_query_id(const memcached_st *self) return self->query_id; } + +org::libmemcached::Instance* memcached_instance_list(const memcached_st *self) +{ + if (self) + { + return (org::libmemcached::Instance*)self->servers; + } + + return NULL; +} + diff --git a/libmemcached/purge.cc b/libmemcached/purge.cc index 841af82e..b45e02a4 100644 --- a/libmemcached/purge.cc +++ b/libmemcached/purge.cc @@ -79,7 +79,7 @@ private: int32_t& _origin; }; -bool memcached_purge(memcached_server_write_instance_st ptr) +bool memcached_purge(org::libmemcached::Instance* ptr) { memcached_st *root= (memcached_st *)ptr->root; diff --git a/libmemcached/quit.cc b/libmemcached/quit.cc index 4bf72f64..cc75bd42 100644 --- a/libmemcached/quit.cc +++ b/libmemcached/quit.cc @@ -46,7 +46,7 @@ will force data to be completed. */ -void memcached_quit_server(memcached_instance_st *ptr, bool io_death) +void memcached_quit_server(org::libmemcached::Instance* ptr, bool io_death) { if (ptr->fd != INVALID_SOCKET) { @@ -138,8 +138,7 @@ void send_quit(memcached_st *ptr) { for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= - memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); memcached_quit_server(instance, false); } diff --git a/libmemcached/quit.hpp b/libmemcached/quit.hpp index 888cde46..76737b95 100644 --- a/libmemcached/quit.hpp +++ b/libmemcached/quit.hpp @@ -36,6 +36,6 @@ #pragma once -void memcached_quit_server(memcached_instance_st *ptr, bool io_death); +void memcached_quit_server(org::libmemcached::Instance* ptr, bool io_death); void send_quit(memcached_st *ptr); diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 809d5b6f..67b0999f 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -38,7 +38,7 @@ #include #include -static memcached_return_t textual_value_fetch(memcached_server_write_instance_st instance, +static memcached_return_t textual_value_fetch(org::libmemcached::Instance* instance, char *buffer, memcached_result_st *result) { @@ -207,7 +207,7 @@ read_error: return MEMCACHED_PARTIAL_READ; } -static memcached_return_t textual_read_one_response(memcached_server_write_instance_st instance, +static memcached_return_t textual_read_one_response(org::libmemcached::Instance* instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { @@ -470,7 +470,7 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta buffer, total_read); } -static memcached_return_t binary_read_one_response(memcached_server_write_instance_st instance, +static memcached_return_t binary_read_one_response(org::libmemcached::Instance* instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { @@ -787,7 +787,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return rc; } -static memcached_return_t _read_one_response(memcached_server_write_instance_st instance, +static memcached_return_t _read_one_response(org::libmemcached::Instance* instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { @@ -817,7 +817,7 @@ static memcached_return_t _read_one_response(memcached_server_write_instance_st return rc; } -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st instance, +memcached_return_t memcached_read_one_response(org::libmemcached::Instance* instance, memcached_result_st *result) { char buffer[SMALL_STRING_LEN]; @@ -831,7 +831,7 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s return _read_one_response(instance, buffer, sizeof(buffer), result); } -memcached_return_t memcached_response(memcached_server_write_instance_st instance, +memcached_return_t memcached_response(org::libmemcached::Instance* instance, memcached_result_st *result) { char buffer[1024]; @@ -839,7 +839,7 @@ memcached_return_t memcached_response(memcached_server_write_instance_st instanc return memcached_response(instance, buffer, sizeof(buffer), result); } -memcached_return_t memcached_response(memcached_server_write_instance_st instance, +memcached_return_t memcached_response(org::libmemcached::Instance* instance, char *buffer, size_t buffer_length, memcached_result_st *result) { diff --git a/libmemcached/response.h b/libmemcached/response.h index 8827aea0..6d6d5644 100644 --- a/libmemcached/response.h +++ b/libmemcached/response.h @@ -38,12 +38,12 @@ #pragma once /* Read a single response from the server */ -memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_read_one_response(org::libmemcached::Instance* ptr, memcached_result_st *result); -memcached_return_t memcached_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_response(org::libmemcached::Instance* ptr, memcached_result_st *result); -memcached_return_t memcached_response(memcached_server_write_instance_st ptr, +memcached_return_t memcached_response(org::libmemcached::Instance* ptr, char *buffer, size_t buffer_length, memcached_result_st *result); diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index cb609257..67a31bbd 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -123,7 +123,7 @@ static void sasl_startup_function(void) } // extern "C" -memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server) +memcached_return_t memcached_sasl_authenticate_connection(org::libmemcached::Instance* server) { if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0) { diff --git a/libmemcached/sasl.hpp b/libmemcached/sasl.hpp index c5d3f81c..c990cfb8 100644 --- a/libmemcached/sasl.hpp +++ b/libmemcached/sasl.hpp @@ -39,4 +39,4 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st *source); -memcached_return_t memcached_sasl_authenticate_connection(memcached_instance_st *server); +memcached_return_t memcached_sasl_authenticate_connection(org::libmemcached::Instance* server); diff --git a/libmemcached/server.cc b/libmemcached/server.cc index a9d7c728..6dca4ab6 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -106,7 +106,7 @@ static memcached_server_st *_server_create(memcached_server_st *self, const memc } memcached_server_st *__server_create_with(memcached_st *memc, - memcached_server_st* self, + memcached_server_st* allocated_instance, const memcached_string_t& hostname, const in_port_t port, uint32_t weight, @@ -118,16 +118,16 @@ memcached_server_st *__server_create_with(memcached_st *memc, return NULL; } - self= _server_create(self, memc); + allocated_instance= _server_create(allocated_instance, memc); - if (self == NULL) + if (allocated_instance == NULL) { return NULL; } - _server_init(self, const_cast(memc), hostname, port, weight, type); + _server_init(allocated_instance, const_cast(memc), hostname, port, weight, type); - return self; + return allocated_instance; } void __server_free(memcached_server_st *self) @@ -208,7 +208,7 @@ in_port_t memcached_server_port(const memcached_server_instance_st self) return 0; } - return self->port; + return self->port(); } uint32_t memcached_server_response_count(const memcached_server_instance_st self) diff --git a/libmemcached/server.hpp b/libmemcached/server.hpp index 191402e8..74816fdc 100644 --- a/libmemcached/server.hpp +++ b/libmemcached/server.hpp @@ -63,17 +63,11 @@ static inline bool memcached_is_valid_servername(const memcached_string_t& arg) return arg.size > 0 or arg.size < NI_MAXHOST; } -static inline void memcached_mark_server_as_clean(memcached_server_write_instance_st server) -{ - server->server_failure_counter= 0; - server->next_retry= 0; -} - -void memcached_instance_free(memcached_instance_st *); +void memcached_instance_free(org::libmemcached::Instance *); -void set_last_disconnected_host(memcached_server_write_instance_st self); +void set_last_disconnected_host(org::libmemcached::Instance* self); -static inline void memcached_mark_server_for_timeout(memcached_server_write_instance_st server) +static inline void memcached_mark_server_for_timeout(org::libmemcached::Instance* server) { if (server->state != MEMCACHED_SERVER_STATE_IN_TIMEOUT) { diff --git a/libmemcached/server_instance.h b/libmemcached/server_instance.h index 69613499..c840384a 100644 --- a/libmemcached/server_instance.h +++ b/libmemcached/server_instance.h @@ -38,11 +38,7 @@ #pragma once #ifdef __cplusplus -extern "C" { -#endif - -typedef struct memcached_instance_st * memcached_server_write_instance_st; - -#ifdef __cplusplus -} +typedef struct org::libmemcached::Instance* memcached_server_write_instance_st; +#else +typedef void* memcached_server_write_instance_st; #endif diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index d2a00922..57d5c7fe 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -126,26 +126,16 @@ uint32_t memcached_instance_list_count(const memcached_st* self) : self->number_of_hosts; } -uint32_t memcached_instance_count(const memcached_instance_st* self) +uint32_t memcached_instance_count(const memcached_st* self) { return (self == NULL) ? 0 : self->number_of_hosts; } -memcached_instance_st *memcached_instance_list(const memcached_st *self) +void memcached_instance_set(memcached_st* memc, org::libmemcached::Instance* list) { - if (self) - { - return self->servers; - } - - return NULL; -} - -void memcached_instance_set(memcached_st *self, memcached_instance_st *list) -{ - self->servers= list; + memc->servers= list; } void memcached_server_list_free(memcached_server_list_st self) @@ -164,7 +154,7 @@ void memcached_server_list_free(memcached_server_list_st self) libmemcached_free(self->root, self); } -void memcached_instance_list_free(memcached_instance_st* self, uint32_t instance_count) +void memcached_instance_list_free(org::libmemcached::Instance* self, uint32_t instance_count) { if (self == NULL) { diff --git a/libmemcached/server_list.hpp b/libmemcached/server_list.hpp index 3dfe5fee..2a8052fa 100644 --- a/libmemcached/server_list.hpp +++ b/libmemcached/server_list.hpp @@ -36,14 +36,14 @@ #pragma once -memcached_instance_st *memcached_instance_list(const memcached_st *); +org::libmemcached::Instance* memcached_instance_list(const memcached_st *); -uint32_t memcached_instance_count(const memcached_instance_st*); +uint32_t memcached_instance_count(const memcached_st*); uint32_t memcached_instance_list_count(const memcached_st*); uint32_t memcached_servers_set_count(memcached_server_list_st servers, uint32_t count); -void memcached_instance_list_free(memcached_instance_st* self, uint32_t count); +void memcached_instance_list_free(org::libmemcached::Instance* self, uint32_t count); -void memcached_instance_set(memcached_st *self, memcached_instance_st* list); +void memcached_instance_set(memcached_st*, org::libmemcached::Instance*); diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index cfe870b9..662edafb 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -346,7 +346,7 @@ char *memcached_stat_get_value(const memcached_st *ptr, memcached_stat_st *memc_ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, const char *args, const size_t args_length, - memcached_server_write_instance_st instance, + org::libmemcached::Instance* instance, struct local_context *check) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -436,7 +436,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, const char *args, const size_t args_length, - memcached_server_write_instance_st instance, + org::libmemcached::Instance* instance, struct local_context *check) { libmemcached_io_vector_st vector[]= @@ -552,7 +552,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu stat_instance->pid= -1; stat_instance->root= self; - memcached_server_write_instance_st instance= memcached_server_instance_fetch(self, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(self, x); memcached_return_t temp_return; if (memcached_is_binary(self)) @@ -613,7 +613,7 @@ memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char if (memcached_success(rc)) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc_ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc_ptr, 0); if (memc.flags.binary_protocol) { rc= binary_stats_fetch(memc_stat, args, args_length, instance, NULL); @@ -675,7 +675,7 @@ void memcached_stat_free(const memcached_st *, memcached_stat_st *memc_stat) } static memcached_return_t call_stat_fn(memcached_st *ptr, - memcached_server_write_instance_st instance, + org::libmemcached::Instance* instance, void *context) { memcached_return_t rc; diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index 88d87fe3..cd29670d 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -139,7 +139,7 @@ static inline uint8_t get_com_code(const memcached_storage_action_t verb, const } static memcached_return_t memcached_send_binary(memcached_st *ptr, - memcached_server_write_instance_st server, + org::libmemcached::Instance* server, uint32_t server_key, const char *key, const size_t key_length, @@ -217,7 +217,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, server_key= 0; } - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); if (memcached_vdo(instance, vector, 5, false) != MEMCACHED_SUCCESS) { @@ -245,7 +245,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } static memcached_return_t memcached_send_ascii(memcached_st *ptr, - memcached_server_write_instance_st instance, + org::libmemcached::Instance* instance, const char *key, const size_t key_length, const char *value, @@ -371,7 +371,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, } uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); WATCHPOINT_SET(instance->io_wait_count.read= 0); WATCHPOINT_SET(instance->io_wait_count.write= 0); diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index 757ddfdf..7a8c7cee 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -38,7 +38,7 @@ #include #include -static memcached_return_t ascii_touch(memcached_server_write_instance_st instance, +static memcached_return_t ascii_touch(org::libmemcached::Instance* instance, const char *key, size_t key_length, time_t expiration) { @@ -70,7 +70,7 @@ static memcached_return_t ascii_touch(memcached_server_write_instance_st instanc return rc; } -static memcached_return_t binary_touch(memcached_server_write_instance_st instance, +static memcached_return_t binary_touch(org::libmemcached::Instance* instance, const char *key, size_t key_length, time_t expiration) { @@ -129,7 +129,7 @@ memcached_return_t memcached_touch_by_key(memcached_st *ptr, } uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, server_key); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); if (ptr->flags.binary_protocol) { diff --git a/libmemcached/udp.cc b/libmemcached/udp.cc index 905eedd7..923e2734 100644 --- a/libmemcached/udp.cc +++ b/libmemcached/udp.cc @@ -48,7 +48,7 @@ * extracts the message number from message_id, increments it and then * writes the new value back into the header */ -void increment_udp_message_id(memcached_server_write_instance_st ptr) +void increment_udp_message_id(org::libmemcached::Instance* ptr) { struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer; uint16_t cur_req= get_udp_datagram_request_id(header); @@ -61,7 +61,7 @@ void increment_udp_message_id(memcached_server_write_instance_st ptr) header->request_id= htons((uint16_t) (thread_id | msg_num)); } -bool memcached_io_init_udp_header(memcached_server_write_instance_st ptr, const uint16_t thread_id) +bool memcached_io_init_udp_header(org::libmemcached::Instance* ptr, const uint16_t thread_id) { if (thread_id > UDP_REQUEST_ID_MAX_THREAD_ID) { diff --git a/libmemcached/udp.hpp b/libmemcached/udp.hpp index 9cc53889..b2d2e9e9 100644 --- a/libmemcached/udp.hpp +++ b/libmemcached/udp.hpp @@ -55,5 +55,5 @@ struct udp_datagram_header_st uint16_t reserved; }; -bool memcached_io_init_udp_header(memcached_server_write_instance_st ptr, const uint16_t thread_id); -void increment_udp_message_id(memcached_server_write_instance_st ptr); +bool memcached_io_init_udp_header(org::libmemcached::Instance*, const uint16_t thread_id); +void increment_udp_message_id(org::libmemcached::Instance*); diff --git a/libmemcached/verbosity.cc b/libmemcached/verbosity.cc index 7b05ef42..4a9918d2 100644 --- a/libmemcached/verbosity.cc +++ b/libmemcached/verbosity.cc @@ -56,7 +56,7 @@ static memcached_return_t _set_verbosity(const memcached_st *, if (rc == MEMCACHED_SUCCESS) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(memc_ptr, 0); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc_ptr, 0); rc= memcached_vdo(instance, vector, 4, true); diff --git a/libmemcached/version.cc b/libmemcached/version.cc index 9f41c97a..5772ef2c 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -52,7 +52,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) bool errors_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); // Optimization, we only fetch version once. if (instance->major_version != UINT8_MAX) @@ -73,7 +73,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) if (success) { // Collect the returned items - memcached_server_write_instance_st instance; + org::libmemcached::Instance* instance; while ((instance= memcached_io_get_readable_server(ptr))) { memcached_return_t rrc= memcached_response(instance, NULL); @@ -104,7 +104,7 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) bool errors_happened= false; for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); initialize_binary_request(instance, request.message.header); @@ -127,7 +127,7 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) if (success) { // Collect the returned items - memcached_server_write_instance_st instance; + org::libmemcached::Instance* instance; while ((instance= memcached_io_get_readable_server(ptr))) { char buffer[32]; diff --git a/tests/libmemcached-1.0/debug.cc b/tests/libmemcached-1.0/debug.cc index 603e15ca..52ac9b25 100644 --- a/tests/libmemcached-1.0/debug.cc +++ b/tests/libmemcached-1.0/debug.cc @@ -67,7 +67,7 @@ static memcached_return_t server_wrapper_for_dump_callback(const memcached_st *, { memcached_st *memc= memcached_create(NULL); - if (server->type == MEMCACHED_CONNECTION_UNIX_SOCKET) + if (strcmp(memcached_server_type(server), "SOCKET") == 0) { if (memcached_failed(memcached_server_add_unix_socket(memc, memcached_server_name(server)))) { diff --git a/tests/libmemcached-1.0/ketama.cc b/tests/libmemcached-1.0/ketama.cc index 1a70e1cb..045ae074 100644 --- a/tests/libmemcached-1.0/ketama.cc +++ b/tests/libmemcached-1.0/ketama.cc @@ -160,7 +160,6 @@ test_return_t user_supplied_bug18(memcached_st *trash) test_return_t auto_eject_hosts(memcached_st *trash) { (void) trash; - memcached_server_instance_st instance; memcached_return_t rc; memcached_st *memc= memcached_create(NULL); @@ -201,8 +200,8 @@ test_return_t auto_eject_hosts(memcached_st *trash) test_true(server_pool[7].port == 11211); test_true(server_pool[7].weight == 100); - instance= memcached_server_instance_by_position(memc, 2); - ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) + 15; + memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 2); + memcached_instance_next_retry(instance, time(NULL) +15); memc->ketama.next_distribution_rebuild= time(NULL) - 1; /* @@ -216,8 +215,9 @@ test_return_t auto_eject_hosts(memcached_st *trash) } /* and re-added when it's back. */ - ((memcached_server_write_instance_st)instance)->next_retry = time(NULL) - 1; - memc->ketama.next_distribution_rebuild= time(NULL) - 1; + time_t absolute_time= time(NULL) -1; + memcached_instance_next_retry(instance, absolute_time); + memc->ketama.next_distribution_rebuild= absolute_time; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, memc->distribution); for (ptrdiff_t x= 0; x < 99; x++) diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 199ee01b..cba7c957 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -299,9 +299,9 @@ static memcached_return_t server_display_unsort_function(const memcached_st*, /* Do Nothing */ uint32_t x= *((uint32_t *)(context)); - if (! (test_ports[x] == server->port)) + if (! (test_ports[x] == memcached_server_port(server))) { - fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)server->port); + fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)memcached_server_port(server)); return MEMCACHED_FAILURE; } @@ -4044,11 +4044,11 @@ test_return_t regression_bug_447342(memcached_st *memc) */ memcached_server_instance_st instance_one= memcached_server_instance_by_position(memc, 0); memcached_server_instance_st instance_two= memcached_server_instance_by_position(memc, 2); - in_port_t port0= instance_one->port; - in_port_t port2= instance_two->port; + in_port_t port0= instance_one->port(); + in_port_t port2= instance_two->port(); - ((memcached_server_write_instance_st)instance_one)->port= 0; - ((memcached_server_write_instance_st)instance_two)->port= 0; + ((memcached_server_write_instance_st)instance_one)->port(0); + ((memcached_server_write_instance_st)instance_two)->port(0); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, @@ -4060,8 +4060,8 @@ test_return_t regression_bug_447342(memcached_st *memc) test_compare(counter, keys.size()); /* restore the memc handle */ - ((memcached_server_write_instance_st)instance_one)->port= port0; - ((memcached_server_write_instance_st)instance_two)->port= port2; + ((memcached_server_write_instance_st)instance_one)->port(port0); + ((memcached_server_write_instance_st)instance_two)->port(port2); memcached_quit(memc); @@ -4076,8 +4076,8 @@ test_return_t regression_bug_447342(memcached_st *memc) } memcached_quit(memc); - ((memcached_server_write_instance_st)instance_one)->port= 0; - ((memcached_server_write_instance_st)instance_two)->port= 0; + ((memcached_server_write_instance_st)instance_one)->port(0); + ((memcached_server_write_instance_st)instance_two)->port(0); /* now retry the command, this time we should have cache misses */ test_compare(MEMCACHED_SUCCESS, @@ -4090,8 +4090,8 @@ test_return_t regression_bug_447342(memcached_st *memc) test_compare(counter, (unsigned int)(keys.size() >> 1)); /* restore the memc handle */ - ((memcached_server_write_instance_st)instance_one)->port= port0; - ((memcached_server_write_instance_st)instance_two)->port= port2; + ((memcached_server_write_instance_st)instance_one)->port(port0); + ((memcached_server_write_instance_st)instance_two)->port(port2); return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/replication.cc b/tests/libmemcached-1.0/replication.cc index 2b79bc15..8f2423c3 100644 --- a/tests/libmemcached-1.0/replication.cc +++ b/tests/libmemcached-1.0/replication.cc @@ -124,10 +124,9 @@ test_return_t replication_get_test(memcached_st *memc) for (uint32_t host= 0; host < memcached_server_count(memc); ++host) { memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc_clone, host); + org::libmemcached::Instance* instance= (org::libmemcached::Instance*)memcached_server_instance_by_position(memc_clone, host); - ((memcached_server_write_instance_st)instance)->port= 0; + instance->port(0); for (int x= 'a'; x <= 'z'; ++x) { @@ -187,9 +186,8 @@ test_return_t replication_mget_test(memcached_st *memc) for (uint32_t host= 0; host < memcached_server_count(memc_clone); host++) { memcached_st *new_clone= memcached_clone(NULL, memc); - memcached_server_instance_st instance= - memcached_server_instance_by_position(new_clone, host); - ((memcached_server_write_instance_st)instance)->port= 0; + memcached_server_instance_st instance= memcached_server_instance_by_position(new_clone, host); + ((memcached_server_write_instance_st)instance)->port(0); for (int x= 'a'; x <= 'z'; ++x) { @@ -332,7 +330,7 @@ test_return_t replication_randomize_mget_fail_test(memcached_st *memc) // We need to now cause a failure in one server, never do this in your own // code. close(memc_clone->servers[1].fd); - memc_clone->servers[1].port= 1; + memc_clone->servers[1].port(1); memc_clone->servers[1].address_info_next= NULL; for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x)