Removed dead param
[m6w6/libmemcached] / libmemcached / hosts.cc
index 337a999aa91c2f397fac641c7a69eaf3fcd22db5..2a07a395c24fe05f24f1ea2d93d880d4387d3747 100644 (file)
@@ -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,11 +62,7 @@ static void sort_hosts(memcached_st *ptr)
 {
   if (memcached_server_count(ptr))
   {
-    memcached_server_write_instance_st instance;
-
-    qsort(memcached_server_list(ptr), memcached_server_count(ptr), sizeof(memcached_server_st), compare_servers);
-    instance= memcached_server_instance_fetch(ptr, 0);
-    instance->number_of_hosts= memcached_server_count(ptr);
+    qsort(memcached_instance_list(ptr), memcached_server_count(ptr), sizeof(org::libmemcached::Instance), compare_servers);
   }
 }
 
@@ -132,7 +128,6 @@ static int continuum_item_cmp(const void *t1, const void *t2)
 static memcached_return_t update_continuum(memcached_st *ptr)
 {
   uint32_t continuum_index= 0;
-  memcached_server_st *list;
   uint32_t pointer_counter= 0;
   uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER;
   uint32_t pointer_per_hash= 1;
@@ -144,7 +139,7 @@ static memcached_return_t update_continuum(memcached_st *ptr)
     return memcached_set_errno(*ptr, errno, MEMCACHED_AT);
   }
 
-  list= memcached_server_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);
@@ -175,7 +170,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;
   }
@@ -223,7 +218,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);
         }
@@ -244,7 +239,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)
@@ -284,7 +279,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",
@@ -296,7 +291,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);
         }
 
@@ -352,19 +347,19 @@ static memcached_return_t server_add(memcached_st *ptr,
 {
   assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st");
 
-  memcached_server_st *new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (ptr->number_of_hosts + 1), memcached_server_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)
   {
     return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
   }
 
-  memcached_server_list_set(ptr, new_host_list);
+  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 (__server_create_with(ptr, instance, hostname, port, weight, type) == NULL)
+  if (__instance_create_with(ptr, instance, hostname, port, weight, type) == NULL)
   {
     return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
   }
@@ -376,10 +371,6 @@ 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);
-  memcached_servers_set_count(instance, memcached_server_count(ptr));
-
   return run_distribution(ptr);
 }
 
@@ -393,30 +384,27 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv
 
   uint32_t count= memcached_server_list_count(list);
 
-  memcached_server_st *new_host_list;
-  new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (count + memcached_server_count(ptr)), memcached_server_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)
   {
     return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
   }
 
-  memcached_server_list_set(ptr, new_host_list);
+  memcached_instance_set(ptr, new_host_list);
 
   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) };
-    if (__server_create_with(ptr, instance, 
-                             hostname,
-                             list[x].port, list[x].weight, list[x].type) == NULL)
+    if (__instance_create_with(ptr, instance, 
+                               hostname,
+                               list[x].port, list[x].weight, list[x].type) == NULL)
     {
       return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
     }
@@ -429,11 +417,48 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv
     ptr->number_of_hosts++;
   }
 
-  // Provides backwards compatibility with server list.
+  return run_distribution(ptr);
+}
+
+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;
+  }
+
+  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)
+  {
+    return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+  }
+
+  memcached_instance_set(ptr, new_host_list);
+
+  for (uint32_t x= 0; x < number_of_hosts; x++)
   {
-    memcached_server_write_instance_st instance;
-    instance= memcached_server_instance_fetch(ptr, 0);
-    instance->number_of_hosts= memcached_server_count(ptr);
+
+    WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
+
+    // We have extended the array, and now we will find it, and use it.
+    org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 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)
+    {
+      return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+    }
+
+    if (list[x].weight > 1)
+    {
+      ptr->ketama.weighted= true;
+    }
+
+    ptr->number_of_hosts++;
   }
 
   return run_distribution(ptr);