X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_hosts.c;h=eb8f45e5f37b61a9b8c6dee2ca2116f363d569d6;hb=a9b22f8a1c9f98eef8becdbef11d8e20d43dd23c;hp=c52aa09621c51d549308385b5019c7ac8b0921fa;hpb=db3442ca6769650638eab10b130a54882045fff0;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index c52aa096..eb8f45e5 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -89,9 +89,10 @@ void server_list_free(memcached_st *ptr, memcached_server_st *servers) static int continuum_item_cmp(const void *t1, const void *t2) { - memcached_continuum_item_st *ct1 = (memcached_continuum_item_st *)t1; - memcached_continuum_item_st *ct2 = (memcached_continuum_item_st *)t2; + memcached_continuum_item_st *ct1= (memcached_continuum_item_st *)t1; + memcached_continuum_item_st *ct2= (memcached_continuum_item_st *)t2; + /* Why 153? Hmmm... */ WATCHPOINT_ASSERT(ct1->value != 153); if (ct1->value == ct2->value) return 0; @@ -169,10 +170,13 @@ memcached_return update_continuum(memcached_st *ptr) pointer_counter+= pointer_per_server; } + WATCHPOINT_ASSERT(ptr); + WATCHPOINT_ASSERT(ptr->continuum); + WATCHPOINT_ASSERT(ptr->number_of_hosts); WATCHPOINT_ASSERT(ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE); - qsort(ptr->continuum, ptr->number_of_hosts * MEMCACHED_POINTS_PER_SERVER, sizeof(memcached_continuum_item_st), continuum_item_cmp); - ptr->continuum_points_counter= pointer_counter; + qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); + if (stat_p) memcached_stat_free(NULL, stat_p); @@ -282,6 +286,32 @@ static memcached_return server_add(memcached_st *ptr, char *hostname, return run_distribution(ptr); } +memcached_return memcached_server_remove(memcached_server_st *st_ptr) +{ + uint32_t x, index; + memcached_st *ptr= st_ptr->root; + memcached_server_st *list= ptr->hosts; + + for (x= 0, index= 0; x < ptr->number_of_hosts; x++) + { + if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH)!=0 || list[x].port != st_ptr->port) + { + memcpy(list+index, list+x, sizeof(memcached_server_st)); + index++; + } + } + ptr->number_of_hosts= index; + + if (st_ptr->address_info) + { + freeaddrinfo(st_ptr->address_info); + st_ptr->address_info= NULL; + } + run_distribution(ptr); + + return MEMCACHED_SUCCESS; +} + memcached_server_st *memcached_server_list_append(memcached_server_st *ptr, char *hostname, unsigned int port, memcached_return *error)