Implemented support for noreply in the binary protocol
[awesomized/libmemcached] / libmemcached / memcached_hosts.c
index df384a9c56911958a8fad6afe709892a08b9a8b6..c0d0f0367c99c84295585db213792bc3151aebad 100644 (file)
@@ -54,22 +54,6 @@ memcached_return run_distribution(memcached_st *ptr)
   return MEMCACHED_SUCCESS;
 }
 
-void host_reset(memcached_st *ptr, memcached_server_st *host, 
-                const char *hostname, unsigned int port, uint32_t weight,
-                memcached_connection type)
-{
-  strncpy(host->hostname, hostname, MEMCACHED_MAX_HOST_LENGTH - 1);
-  host->root= ptr ? ptr : NULL;
-  host->port= port;
-  host->weight= weight;
-  host->fd= -1;
-  host->type= type;
-  host->read_ptr= host->read_buffer;
-  if (ptr)
-    host->next_retry= ptr->retry_timeout;
-  host->sockaddr_inited= MEMCACHED_NOT_ALLOCATED;
-}
-
 void server_list_free(memcached_st *ptr, memcached_server_st *servers)
 {
   unsigned int x;
@@ -133,14 +117,19 @@ memcached_return update_continuum(memcached_st *ptr)
   is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
   points_per_server= is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER;
 
+  if (ptr->number_of_hosts == 0)
+    return MEMCACHED_SUCCESS;
+
   if (ptr->number_of_hosts > ptr->continuum_count)
   {
     memcached_continuum_item_st *new_ptr;
 
     if (ptr->call_realloc)
-      new_ptr= (memcached_continuum_item_st *)ptr->call_realloc(ptr, ptr->continuum, sizeof(memcached_continuum_item_st) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * points_per_server);
+      new_ptr= (memcached_continuum_item_st *)ptr->call_realloc(ptr, ptr->continuum, 
+                                                                sizeof(memcached_continuum_item_st) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * points_per_server);
     else
-      new_ptr= (memcached_continuum_item_st *)realloc(ptr->continuum, sizeof(memcached_continuum_item_st) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * points_per_server);
+      new_ptr= (memcached_continuum_item_st *)realloc(ptr->continuum, 
+                                                      sizeof(memcached_continuum_item_st) * (ptr->number_of_hosts + MEMCACHED_CONTINUUM_ADDITION) * points_per_server);
 
     if (new_ptr == 0)
       return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
@@ -208,7 +197,7 @@ memcached_return update_continuum(memcached_st *ptr)
       }
       else
       {
-        value= generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum);
+        value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum);
         ptr->continuum[continuum_index].index= host_index;
         ptr->continuum[continuum_index++].value= value;
       }
@@ -260,8 +249,10 @@ memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *l
   for (x= 0; x < count; x++)
   {
     WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
-    host_reset(ptr, &ptr->hosts[ptr->number_of_hosts], list[x].hostname, 
-               list[x].port, list[x].weight, list[x].type);
+    memcached_server_create(ptr, &ptr->hosts[ptr->number_of_hosts]);
+    /* TODO check return type */
+    (void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], list[x].hostname, 
+                                       list[x].port, list[x].weight, list[x].type);
     ptr->number_of_hosts++;
   }
   ptr->hosts[0].count= ptr->number_of_hosts;
@@ -345,7 +336,8 @@ static memcached_return server_add(memcached_st *ptr, const char *hostname,
 
   ptr->hosts= new_host_list;
 
-  host_reset(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, weight, type);
+  /* TODO: Check return type */
+  (void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, weight, type);
   ptr->number_of_hosts++;
   ptr->hosts[0].count= ptr->number_of_hosts;
 
@@ -414,7 +406,8 @@ memcached_server_st *memcached_server_list_append_with_weight(memcached_server_s
     return NULL;
   }
 
-  host_reset(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP);
+  /* TODO: Check return type */
+  memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP);
 
   /* Backwards compatibility hack */
   new_host_list[0].count= count;