From: Brian Aker Date: Sun, 16 Dec 2012 19:51:48 +0000 (-0500) Subject: First pass in cleaning up instance. X-Git-Tag: 1.0.15^2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7acbb1495e0aaa29df7ffb09b90ec97fc949c48d;p=m6w6%2Flibmemcached First pass in cleaning up instance. --- diff --git a/libmemcached/common.h b/libmemcached/common.h index 53e083a4..cc38b56d 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -111,7 +111,9 @@ #include #include -#include +#ifdef __cplusplus +# include "libmemcached/instance.hpp" +#endif #include #ifdef HAVE_POLL_H diff --git a/libmemcached/flush.cc b/libmemcached/flush.cc index 1e1533dd..7a102eab 100644 --- a/libmemcached/flush.cc +++ b/libmemcached/flush.cc @@ -86,7 +86,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, { org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); - if (memcached_instance_response_count(instance) > 0) + if (instance->response_count() > 0) { (void)memcached_response(instance, NULL, 0, NULL); } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index b774e7d5..88f8b56a 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -246,7 +246,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, { org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); - if (memcached_instance_response_count(instance)) + if (instance->response_count()) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -255,7 +255,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, memcached_io_write(instance); } - while(memcached_instance_response_count(instance)) + while(instance->response_count()) { (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result); } @@ -304,7 +304,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, }; - if (memcached_instance_response_count(instance) == 0) + if (instance->response_count() == 0) { rc= memcached_connect(instance); @@ -356,7 +356,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, { org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); - if (memcached_instance_response_count(instance)) + if (instance->response_count()) { /* We need to do something about non-connnected hosts in the future */ if ((memcached_io_write(instance, "\r\n", 2, true)) == -1) @@ -480,7 +480,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key); - if (memcached_instance_response_count(instance) == 0) + if (instance->response_count() == 0) { rc= memcached_connect(instance); if (memcached_failed(rc)) @@ -554,7 +554,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); initialize_binary_request(instance, request.message.header); - if (memcached_instance_response_count(instance)) + if (instance->response_count()) { if (memcached_io_write(instance) == false) { @@ -624,7 +624,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server); - if (memcached_instance_response_count(instance) == 0) + if (instance->response_count() == 0) { rc= memcached_connect(instance); diff --git a/libmemcached/include.am b/libmemcached/include.am index e026e1a0..6dbcb167 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -26,7 +26,6 @@ noinst_HEADERS+= libmemcached/encoding_key.h noinst_HEADERS+= libmemcached/error.hpp noinst_HEADERS+= libmemcached/flag.hpp noinst_HEADERS+= libmemcached/initialize_query.h -noinst_HEADERS+= libmemcached/instance.h noinst_HEADERS+= libmemcached/instance.hpp noinst_HEADERS+= libmemcached/internal.h noinst_HEADERS+= libmemcached/io.h diff --git a/libmemcached/instance.cc b/libmemcached/instance.cc index 41f491e8..dea8dd62 100644 --- a/libmemcached/instance.cc +++ b/libmemcached/instance.cc @@ -170,31 +170,10 @@ void __instance_free(org::libmemcached::Instance* self) void memcached_instance_free(org::libmemcached::Instance* self) { - if (self == NULL) - { - 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(org::libmemcached::Instance* source) -{ - /* We just do a normal create if source is missing */ - if (source == NULL) + if (self) { - return NULL; + __instance_free(self); } - - memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; - return __server_create_with(source->root, NULL, - hostname, - source->port(), source->weight, - source->type); - } memcached_return_t memcached_server_cursor(const memcached_st *ptr, @@ -341,26 +320,6 @@ memcached_server_instance_st memcached_server_get_last_disconnect(const memcache return (memcached_server_instance_st)self->last_disconnected_server; } -const char *memcached_instance_name(const memcached_server_instance_st self) -{ - WATCHPOINT_ASSERT(self); - if (self == NULL) - return NULL; - - return self->hostname; -} - -in_port_t memcached_instance_port(const memcached_server_instance_st self) -{ - WATCHPOINT_ASSERT(self); - if (self == NULL) - { - return 0; - } - - return self->port(); -} - void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time) { WATCHPOINT_ASSERT(self); @@ -369,14 +328,3 @@ void memcached_instance_next_retry(memcached_server_instance_st self, const time ((org::libmemcached::Instance*)self)->next_retry= absolute_time; } } - -uint32_t memcached_instance_response_count(const org::libmemcached::Instance* self) -{ - WATCHPOINT_ASSERT(self); - if (self == NULL) - { - return 0; - } - - return self->cursor_active_; -} diff --git a/libmemcached/instance.h b/libmemcached/instance.h deleted file mode 100644 index e564afaa..00000000 --- a/libmemcached/instance.h +++ /dev/null @@ -1,139 +0,0 @@ -/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * Libmemcached library - * - * Copyright (C) 2012 Data Differential, http://datadifferential.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -#pragma once - -#ifndef WIN32 -# ifdef HAVE_NETDB_H -# include -# endif -#endif - -#ifdef NI_MAXHOST -# define MEMCACHED_NI_MAXHOST NI_MAXHOST -#else -# define MEMCACHED_NI_MAXHOST 1025 -#endif - -#ifdef NI_MAXSERV -# define MEMCACHED_NI_MAXSERV NI_MAXSERV -#else -# define MEMCACHED_NI_MAXSERV 32 -#endif - -#ifdef __cplusplus - -namespace org { -namespace libmemcached { - -// @todo Complete class transformation -struct Instance { - in_port_t port() const - { - return port_; - } - - void port(in_port_t arg) - { - port_= arg; - } - - void mark_server_as_clean() - { - server_failure_counter= 0; - next_retry= 0; - } - - void disable() - { - } - - void enable() - { - } - - uint32_t response_count() const - { - return cursor_active_; - } - - struct { - bool is_allocated:1; - bool is_initialized:1; - bool is_shutting_down:1; - bool is_dead:1; - } options; - uint32_t cursor_active_; - in_port_t port_; - memcached_socket_t fd; - uint32_t io_bytes_sent; /* # bytes sent since last read */ - uint32_t request_id; - uint32_t server_failure_counter; - uint64_t server_failure_counter_query_id; - uint32_t weight; - uint32_t version; - enum memcached_server_state_t state; - struct { - uint32_t read; - uint32_t write; - uint32_t timeouts; - size_t _bytes_read; - } io_wait_count; - uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set. - uint8_t micro_version; // ditto, and note that this is the third, not second version bit - uint8_t minor_version; // ditto - memcached_connection_t type; - char *read_ptr; - size_t read_buffer_length; - size_t read_data_length; - size_t write_buffer_offset; - struct addrinfo *address_info; - struct addrinfo *address_info_next; - time_t next_retry; - struct memcached_st *root; - uint64_t limit_maxbytes; - struct memcached_error_t *error_messages; - char read_buffer[MEMCACHED_MAX_BUFFER]; - 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 e8d44058..fba02b2f 100644 --- a/libmemcached/instance.hpp +++ b/libmemcached/instance.hpp @@ -38,6 +38,102 @@ #pragma once +#ifndef WIN32 +# ifdef HAVE_NETDB_H +# include +# endif +#endif + +#ifdef NI_MAXHOST +# define MEMCACHED_NI_MAXHOST NI_MAXHOST +#else +# define MEMCACHED_NI_MAXHOST 1025 +#endif + +#ifdef NI_MAXSERV +# define MEMCACHED_NI_MAXSERV NI_MAXSERV +#else +# define MEMCACHED_NI_MAXSERV 32 +#endif + +namespace org { +namespace libmemcached { + +// @todo Complete class transformation +struct Instance { + in_port_t port() const + { + return port_; + } + + void port(in_port_t arg) + { + port_= arg; + } + + void mark_server_as_clean() + { + server_failure_counter= 0; + next_retry= 0; + } + + void disable() + { + } + + void enable() + { + } + + uint32_t response_count() const + { + return cursor_active_; + } + + struct { + bool is_allocated:1; + bool is_initialized:1; + bool is_shutting_down:1; + bool is_dead:1; + } options; + uint32_t cursor_active_; + in_port_t port_; + memcached_socket_t fd; + uint32_t io_bytes_sent; /* # bytes sent since last read */ + uint32_t request_id; + uint32_t server_failure_counter; + uint64_t server_failure_counter_query_id; + uint32_t weight; + uint32_t version; + enum memcached_server_state_t state; + struct { + uint32_t read; + uint32_t write; + uint32_t timeouts; + size_t _bytes_read; + } io_wait_count; + uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set. + uint8_t micro_version; // ditto, and note that this is the third, not second version bit + uint8_t minor_version; // ditto + memcached_connection_t type; + char *read_ptr; + size_t read_buffer_length; + size_t read_data_length; + size_t write_buffer_offset; + struct addrinfo *address_info; + struct addrinfo *address_info_next; + time_t next_retry; + struct memcached_st *root; + uint64_t limit_maxbytes; + struct memcached_error_t *error_messages; + char read_buffer[MEMCACHED_MAX_BUFFER]; + char write_buffer[MEMCACHED_MAX_BUFFER]; + char hostname[MEMCACHED_NI_MAXHOST]; +}; + +} // namespace libmemcached +} // namespace org + org::libmemcached::Instance* __instance_create_with(memcached_st *memc, org::libmemcached::Instance* self, const memcached_string_t& hostname, @@ -45,14 +141,6 @@ org::libmemcached::Instance* __instance_create_with(memcached_st *memc, uint32_t weight, const memcached_connection_t type); -const char *memcached_instance_name(const org::libmemcached::Instance* self); - -in_port_t memcached_instance_port(const org::libmemcached::Instance* self); - 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_response_count(const org::libmemcached::Instance* self); - void __instance_free(org::libmemcached::Instance *); diff --git a/libmemcached/io.cc b/libmemcached/io.cc index b1f1327c..8cee0178 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -742,7 +742,7 @@ org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc return instance; } - if (memcached_instance_response_count(instance) > 0) + if (instance->response_count() > 0) { fds[host_index].events= POLLIN; fds[host_index].revents= 0; @@ -758,7 +758,7 @@ org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc { org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); - if (memcached_instance_response_count(instance) > 0) + if (instance->response_count() > 0) { return instance; } diff --git a/tests/failure.cc b/tests/failure.cc index abba57ed..b55d68ab 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -102,7 +102,7 @@ static test_return_t restart_servers(memcached_st *) return TEST_SUCCESS; } -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" static test_return_t cull_TEST(memcached_st *memc) { uint32_t count= memcached_server_count(memc); diff --git a/tests/libmemcached-1.0/debug.cc b/tests/libmemcached-1.0/debug.cc index 6beccc85..f7d4b34c 100644 --- a/tests/libmemcached-1.0/debug.cc +++ b/tests/libmemcached-1.0/debug.cc @@ -46,7 +46,7 @@ using namespace libtest; #include #include -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" /* Dump each server's keys */ static memcached_return_t print_keys_callback(const memcached_st *, diff --git a/tests/libmemcached-1.0/ketama.cc b/tests/libmemcached-1.0/ketama.cc index 2fd726a6..44fefc7e 100644 --- a/tests/libmemcached-1.0/ketama.cc +++ b/tests/libmemcached-1.0/ketama.cc @@ -41,7 +41,7 @@ #include "libmemcached/server_instance.h" #include "libmemcached/continuum.hpp" -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" #include #include diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 81d63506..068d5197 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -92,7 +92,7 @@ using namespace libtest; #include "tests/keys.hpp" -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options) { diff --git a/tests/libmemcached-1.0/parser.cc b/tests/libmemcached-1.0/parser.cc index 33f95c5a..2e8e5cd6 100644 --- a/tests/libmemcached-1.0/parser.cc +++ b/tests/libmemcached-1.0/parser.cc @@ -49,7 +49,7 @@ using namespace libtest; #include #include -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" enum scanner_type_t { diff --git a/tests/libmemcached-1.0/pool.cc b/tests/libmemcached-1.0/pool.cc index 2e008d39..30cc9660 100644 --- a/tests/libmemcached-1.0/pool.cc +++ b/tests/libmemcached-1.0/pool.cc @@ -55,7 +55,7 @@ using namespace libtest; #include #include -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wstrict-aliasing" diff --git a/tests/libmemcached-1.0/replication.cc b/tests/libmemcached-1.0/replication.cc index 363eaadb..1a22a220 100644 --- a/tests/libmemcached-1.0/replication.cc +++ b/tests/libmemcached-1.0/replication.cc @@ -113,7 +113,7 @@ test_return_t replication_set_test(memcached_st *memc) return TEST_SUCCESS; } -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" test_return_t replication_get_test(memcached_st *memc) { diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index 6e282d55..d5924471 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -63,7 +63,7 @@ using namespace libtest; #include -#include "libmemcached/instance.h" +#include "libmemcached/instance.hpp" #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wstrict-aliasing"