X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_hosts.c;h=2bcd189c15ab3fce95eba0970a039743b848af3b;hb=baf931721d1b37ac06ea5126ac038cca2d413d91;hp=30c8f954c697de6e8502558edb65a880f941d28c;hpb=27bc5952905705b7113b338c9d805825dab3075c;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 30c8f954..2bcd189c 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -117,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; @@ -192,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; } @@ -243,6 +248,11 @@ memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *l for (x= 0; x < count; x++) { + if ((ptr->flags & MEM_USE_UDP && list[x].type != MEMCACHED_CONNECTION_UDP) + || ((list[x].type == MEMCACHED_CONNECTION_UDP) + && ! (ptr->flags & MEM_USE_UDP)) ) + return MEMCACHED_INVALID_HOST_PROTOCOL; + WATCHPOINT_ASSERT(list[x].hostname[0] != 0); memcached_server_create(ptr, &ptr->hosts[ptr->number_of_hosts]); /* TODO check return type */ @@ -308,7 +318,7 @@ memcached_return memcached_server_add_with_weight(memcached_st *ptr, port= MEMCACHED_DEFAULT_PORT; if (!hostname) - hostname= "localhost"; + hostname= "localhost"; return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP); } @@ -320,6 +330,10 @@ static memcached_return server_add(memcached_st *ptr, const char *hostname, { memcached_server_st *new_host_list; + if ( (ptr->flags & MEM_USE_UDP && type != MEMCACHED_CONNECTION_UDP) + || ( (type == MEMCACHED_CONNECTION_UDP) && !(ptr->flags & MEM_USE_UDP) ) ) + return MEMCACHED_INVALID_HOST_PROTOCOL; + if (ptr->call_realloc) new_host_list= (memcached_server_st *)ptr->call_realloc(ptr, ptr->hosts, sizeof(memcached_server_st) * (ptr->number_of_hosts+1));