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;
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;
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;
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;
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;