First pass in cleaning up instance.
[m6w6/libmemcached] / libmemcached / instance.cc
index aacdad64a3d2262f92a4e137a6c5250e32715c46..dea8dd62d10f512477391400f5f56b58f816a763 100644 (file)
@@ -154,6 +154,7 @@ void __instance_free(org::libmemcached::Instance* self)
     self->address_info= NULL;
     self->address_info_next= NULL;
   }
+  assert(self->address_info_next == NULL);
 
   memcached_error_free(*self);
 
@@ -169,31 +170,10 @@ void __instance_free(org::libmemcached::Instance* self)
 
 void memcached_instance_free(org::libmemcached::Instance* self)
 {
-  if (self == NULL)
+  if (self)
   {
-    return;
+    __instance_free(self);
   }
-
-  __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)
-  {
-    return NULL;
-  }
-
-  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,
@@ -307,46 +287,29 @@ static org::libmemcached::Instance* memcached_instance_clone(org::libmemcached::
 void set_last_disconnected_host(org::libmemcached::Instance* self)
 {
   assert(self->root);
-  if (self->root == NULL)
+  if (self->root)
   {
-    return;
-  }
+    if (memcached_server_get_last_disconnect(self->root) and
+        memcached_server_get_last_disconnect(self->root)->version == self->version)
+    {
+      return;
+    }
 
-  if (memcached_server_get_last_disconnect(self->root) and
-      memcached_server_get_last_disconnect(self->root)->version == self->version)
-  {
-    return;
-  }
+    // const_cast
+    memcached_st *root= (memcached_st *)self->root;
 
-  // const_cast
-  memcached_st *root= (memcached_st *)self->root;
+    memcached_instance_free((org::libmemcached::Instance*)(root->last_disconnected_server));
 
-  memcached_instance_free((org::libmemcached::Instance*)(root->last_disconnected_server));
-  root->last_disconnected_server= memcached_instance_clone(self);
-  ((org::libmemcached::Instance*)memcached_server_get_last_disconnect(root))->version= self->version;
-}
+    // We set is_parsing so that no lookup happens
+    root->state.is_parsing= true;
+    root->last_disconnected_server= memcached_instance_clone(self);
+    root->state.is_parsing= false;
 
-memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
-{
-  WATCHPOINT_ASSERT(self);
-  if (self == NULL)
-  {
-    return 0;
+    ((org::libmemcached::Instance*)memcached_server_get_last_disconnect(root))->version= self->version;
   }
-
-  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)
+memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *self)
 {
   WATCHPOINT_ASSERT(self);
   if (self == NULL)
@@ -354,7 +317,7 @@ in_port_t memcached_instance_port(const memcached_server_instance_st self)
     return 0;
   }
 
-  return self->port();
+  return (memcached_server_instance_st)self->last_disconnected_server;
 }
 
 void memcached_instance_next_retry(memcached_server_instance_st self, const time_t absolute_time)
@@ -365,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_;
-}