First pass in cleaning up instance.
authorBrian Aker <brian@tangent.org>
Sun, 16 Dec 2012 19:51:48 +0000 (14:51 -0500)
committerBrian Aker <brian@tangent.org>
Sun, 16 Dec 2012 19:51:48 +0000 (14:51 -0500)
16 files changed:
libmemcached/common.h
libmemcached/flush.cc
libmemcached/get.cc
libmemcached/include.am
libmemcached/instance.cc
libmemcached/instance.h [deleted file]
libmemcached/instance.hpp
libmemcached/io.cc
tests/failure.cc
tests/libmemcached-1.0/debug.cc
tests/libmemcached-1.0/ketama.cc
tests/libmemcached-1.0/mem_functions.cc
tests/libmemcached-1.0/parser.cc
tests/libmemcached-1.0/pool.cc
tests/libmemcached-1.0/replication.cc
tests/mem_udp.cc

index 53e083a433cd45f6849d4479fb5301d1a3e12734..cc38b56d49f42e9d9409750ec8830bcfdbb7036d 100644 (file)
 #include <libmemcached/watchpoint.h>
 #include <libmemcached/is.h>
 
-#include <libmemcached/instance.h>
+#ifdef __cplusplus
+# include "libmemcached/instance.hpp"
+#endif
 #include <libmemcached/server_instance.h>
 
 #ifdef HAVE_POLL_H
index 1e1533ddaf35a2af31bec0a85a181670ba50d327..7a102eab2cb96bbdf4c3d141e2213226c905f867 100644 (file)
@@ -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);
     }
index b774e7d5e775eea011caff5d2171d93d39378578..88f8b56a1ed4285814c3248cbb47304cb8459d88 100644 (file)
@@ -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);
 
index e026e1a0226be24b09a463378afa937a48e337da..6dbcb167c3460980035a271d3499ea0096752019 100644 (file)
@@ -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 
index 41f491e8ef2d0e01f8af73dff0227ca7ef73b9fc..dea8dd62d10f512477391400f5f56b58f816a763 100644 (file)
@@ -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 (file)
index e564afa..0000000
+++ /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 <netdb.h>
-# 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
index e8d44058a535dffa75ca0a6a3c5fb233f35786af..fba02b2f4da0f2be1afb39fe5fe5b1f70b8cbb69 100644 (file)
 
 #pragma once
 
+#ifndef WIN32
+# ifdef HAVE_NETDB_H
+#  include <netdb.h>
+# 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 *);
index b1f1327c489b47da6111a2dec1763c97d380157b..8cee0178711eeff6587cc8ded3ae226bfa79c2fa 100644 (file)
@@ -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;
       }
index abba57ed4718e1186f00f731d23f58890ea4cf64..b55d68abfb346ad7653a48eab9b564588bc09316 100644 (file)
@@ -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);
index 6beccc85f12b0a76a48fb6190c3cbf42a6434083..f7d4b34c8d9cc979e79e8cdae88d883e5bcbcb3d 100644 (file)
@@ -46,7 +46,7 @@ using namespace libtest;
 #include <tests/debug.h>
 #include <tests/print.h>
 
-#include "libmemcached/instance.h"
+#include "libmemcached/instance.hpp"
 
 /* Dump each server's keys */
 static memcached_return_t print_keys_callback(const memcached_st *,
index 2fd726a65a175b0d54970458b85d0b68659957ff..44fefc7e5d897299c5d385d9ec6dd884683bea7d 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "libmemcached/server_instance.h"
 #include "libmemcached/continuum.hpp"
-#include "libmemcached/instance.h"
+#include "libmemcached/instance.hpp"
 
 #include <tests/ketama.h>
 #include <tests/ketama_test_cases.h>
index 81d635067ee60012cd1ae363f22ca3e51dd74d11..068d5197414368f5a84b6f5befb3a105106dc541 100644 (file)
@@ -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)
 {
index 33f95c5a6d62f52ed2e68ed809909dc4b44236bd..2e8e5cd6464b70b01ffd82eb455ff9071f186777 100644 (file)
@@ -49,7 +49,7 @@ using namespace libtest;
 
 #include <tests/libmemcached-1.0/parser.h>
 #include <tests/print.h>
-#include "libmemcached/instance.h"
+#include "libmemcached/instance.hpp"
 
 enum scanner_type_t
 {
index 2e008d39c79231936ac362ab272e9061c96c3465..30cc9660a06e7ad1c244d50c01c1ee7464170d1a 100644 (file)
@@ -55,7 +55,7 @@ using namespace libtest;
 #include <pthread.h>
 #include <poll.h>
 
-#include "libmemcached/instance.h"
+#include "libmemcached/instance.hpp"
 
 #ifndef __INTEL_COMPILER
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
index 363eaadbcb57eb7daa72a090ab47e51d0f728cf9..1a22a2207b18abf411bd858b3ec88321401dc102 100644 (file)
@@ -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)
 {
index 6e282d557d8c0ae88888092368c9eb1e72215898..d59244715f7e127af7812487c9d8bfe5a6b8f245 100644 (file)
@@ -63,7 +63,7 @@ using namespace libtest;
 
 #include <libtest/server.h>
 
-#include "libmemcached/instance.h"
+#include "libmemcached/instance.hpp"
 
 #ifndef __INTEL_COMPILER
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"