X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fhosts.cc;h=32bf8ce37d9301bd6139feb77aecb041e1e3a07b;hb=dc9533f1e17289d98c9fc7e5bb953774f625c033;hp=4aee163cda51781d665c2422fe807b70342a1e4c;hpb=f0b9c972a973d997db6660680938dd5acb2baa46;p=m6w6%2Flibmemcached diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 4aee163c..32bf8ce3 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -186,7 +186,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) memcached_continuum_item_st *new_ptr; new_ptr= static_cast(libmemcached_realloc(ptr, ptr->ketama.continuum, - sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server)); + sizeof(memcached_continuum_item_st) * (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server)); if (new_ptr == 0) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; @@ -259,8 +259,8 @@ static memcached_return_t update_continuum(memcached_st *ptr) for (uint32_t x= 0; x < pointer_per_hash; x++) { uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x); - ptr->ketama.continuum[continuum_index].index= host_index; - ptr->ketama.continuum[continuum_index++].value= value; + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } else @@ -307,9 +307,9 @@ static memcached_return_t update_continuum(memcached_st *ptr) { for (uint32_t x = 0; x < pointer_per_hash; x++) { - uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x); - ptr->ketama.continuum[continuum_index].index= host_index; - ptr->ketama.continuum[continuum_index++].value= value; + uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x); + ptr->ketama.continuum[continuum_index].index= host_index; + ptr->ketama.continuum[continuum_index++].value= value; } } else @@ -325,7 +325,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) } WATCHPOINT_ASSERT(ptr); - WATCHPOINT_ASSERT(ptr->continuum); + WATCHPOINT_ASSERT(ptr->ketama.continuum); WATCHPOINT_ASSERT(memcached_server_count(ptr) * MEMCACHED_POINTS_PER_SERVER <= MEMCACHED_CONTINUUM_SIZE); ptr->ketama.continuum_points_counter= pointer_counter; qsort(ptr->ketama.continuum, ptr->ketama.continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); @@ -333,7 +333,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) #ifdef DEBUG for (uint32_t pointer_index= 0; memcached_server_count(ptr) && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++) { - WATCHPOINT_ASSERT(ptr->continuum[pointer_index].value <= ptr->continuum[pointer_index + 1].value); + WATCHPOINT_ASSERT(ptr->ketama.continuum[pointer_index].value <= ptr->ketama.continuum[pointer_index + 1].value); } #endif @@ -448,10 +448,10 @@ memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, in_port_t port, uint32_t weight) { - if (! port) + if (not port) port= MEMCACHED_DEFAULT_PORT; - if (! hostname) + if (not hostname) hostname= "localhost"; return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_TCP); @@ -462,23 +462,23 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, uint32_t weight, memcached_connection_t type) { - memcached_server_st *new_host_list; - memcached_server_write_instance_st instance; - if ( (ptr->flags.use_udp && type != MEMCACHED_CONNECTION_UDP) - || ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) ) + if ( (ptr->flags.use_udp and type != MEMCACHED_CONNECTION_UDP) + or ( (type == MEMCACHED_CONNECTION_UDP) and (not ptr->flags.use_udp) ) ) + { return MEMCACHED_INVALID_HOST_PROTOCOL; + } - new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), - sizeof(memcached_server_st) * (ptr->number_of_hosts + 1))); + memcached_server_st *new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), + sizeof(memcached_server_st) * (ptr->number_of_hosts + 1))); - if (new_host_list == NULL) + if (not new_host_list) return MEMCACHED_MEMORY_ALLOCATION_FAILURE; memcached_server_list_set(ptr, new_host_list); /* TODO: Check return type */ - instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); (void)memcached_server_create_with(ptr, instance, hostname, port, weight, type); @@ -494,3 +494,20 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, return run_distribution(ptr); } + +memcached_return_t memcached_server_add_parsed(memcached_st *ptr, + const char *hostname, + size_t hostname_length, + in_port_t port, + uint32_t weight) +{ + char buffer[NI_MAXHOST]; + + memcpy(buffer, hostname, hostname_length); + buffer[hostname_length]= 0; + + return server_add(ptr, buffer, + port, + weight, + MEMCACHED_CONNECTION_TCP); +}