X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=inline;f=libmemcached%2Fhosts.cc;h=fe3c977a86971b2891a8271c034726b8a962b03c;hb=5ed5a750b9ae6e4e577232ecf50dc333eb414298;hp=5c4cf175e095a9e08e3736bf51275def28fba2ad;hpb=969fea8e7bed82c109685ec3976cf7b0ec514ae9;p=m6w6%2Flibmemcached diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 5c4cf175..fe3c977a 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -45,11 +45,10 @@ static memcached_return_t update_continuum(memcached_st *ptr); static int compare_servers(const void *p1, const void *p2) { - int return_value; memcached_server_instance_st a= (memcached_server_instance_st)p1; memcached_server_instance_st b= (memcached_server_instance_st)p2; - return_value= strcmp(a->hostname, b->hostname); + int return_value= strcmp(a->hostname, b->hostname); if (return_value == 0) { @@ -219,7 +218,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (is_ketama_weighted) { float pct= (float)list[host_index].weight / (float)total_weight; - pointer_per_server= (uint32_t) ((floorf((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4); + pointer_per_server= (uint32_t) ((floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4); pointer_per_hash= 4; if (DEBUG) { @@ -353,18 +352,13 @@ static memcached_return_t server_add(memcached_st *ptr, memcached_connection_t type) { assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); - if ( (ptr->flags.use_udp and type != MEMCACHED_CONNECTION_UDP) - or ( (type == MEMCACHED_CONNECTION_UDP) and (not ptr->flags.use_udp) ) ) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_AT); - } 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 (not new_host_list) + if (new_host_list == NULL) { - return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } memcached_server_list_set(ptr, new_host_list); @@ -372,7 +366,7 @@ static memcached_return_t server_add(memcached_st *ptr, /* TODO: Check return type */ memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); - if (not __server_create_with(ptr, instance, hostname, port, weight, type)) + if (__server_create_with(ptr, instance, hostname, port, weight, type) == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } @@ -394,7 +388,7 @@ static memcached_return_t server_add(memcached_st *ptr, memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) { - if (not list) + if (list == NULL) { return MEMCACHED_SUCCESS; } @@ -405,8 +399,10 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), sizeof(memcached_server_st) * (count + memcached_server_count(ptr)))); - if (not new_host_list) + if (new_host_list == NULL) + { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } memcached_server_list_set(ptr, new_host_list); @@ -414,12 +410,6 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv { memcached_server_write_instance_st instance; - if ((ptr->flags.use_udp && list[x].type != MEMCACHED_CONNECTION_UDP) - or ((list[x].type == MEMCACHED_CONNECTION_UDP) and not (ptr->flags.use_udp)) ) - { - return MEMCACHED_INVALID_HOST_PROTOCOL; - } - WATCHPOINT_ASSERT(list[x].hostname[0] != 0); // We have extended the array, and now we will find it, and use it. @@ -484,32 +474,16 @@ memcached_return_t memcached_server_add_udp(memcached_st *ptr, } memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, - const char *hostname, - in_port_t port, - uint32_t weight) + const char *, + in_port_t, + uint32_t) { if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; } - if (not port) - { - port= MEMCACHED_DEFAULT_PORT; - } - - if (not hostname) - { - hostname= "localhost"; - } - - memcached_string_t _hostname= { memcached_string_make_from_cstr(hostname) }; - if (memcached_is_valid_servername(_hostname) == false) - { - memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided")); - } - - return server_add(ptr, _hostname, port, weight, MEMCACHED_CONNECTION_UDP); + return memcached_set_error(*ptr, MEMCACHED_DEPRECATED, MEMCACHED_AT); } memcached_return_t memcached_server_add(memcached_st *ptr, @@ -538,7 +512,7 @@ memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, if (hostname_length == 0) { hostname= "localhost"; - hostname_length= sizeof("localhost") -1; + hostname_length= memcached_literal_param_size("localhost"); } memcached_string_t _hostname= { hostname, hostname_length };