X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fhosts.cc;h=4acc3cddb9791ed02348f650c0e6bc2032fd3d4a;hb=ade26d9f2de230a6b9ce3cd45f909c56f529852a;hp=152ff703b6ef38433c6571b2d4de095f7db609f9;hpb=b16fffff43d822239ce79a366ec36873b0803df9;p=awesomized%2Flibmemcached diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 152ff703..4acc3cdd 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -140,10 +140,9 @@ static memcached_return_t update_continuum(memcached_st *ptr) uint32_t live_servers= 0; struct timeval now; - if (gettimeofday(&now, NULL) != 0) + if (gettimeofday(&now, NULL)) { - memcached_set_errno(ptr, errno, NULL); - return MEMCACHED_ERRNO; + return memcached_set_errno(*ptr, errno, MEMCACHED_AT); } list= memcached_server_list(ptr); @@ -157,11 +156,15 @@ static memcached_return_t update_continuum(memcached_st *ptr) for (uint32_t host_index= 0; host_index < memcached_server_count(ptr); ++host_index) { if (list[host_index].next_retry <= now.tv_sec) + { live_servers++; + } else { if (ptr->ketama.next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->ketama.next_distribution_rebuild) + { ptr->ketama.next_distribution_rebuild= list[host_index].next_retry; + } } } } @@ -173,8 +176,10 @@ static memcached_return_t update_continuum(memcached_st *ptr) uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER); - if (live_servers == 0) + if (not live_servers) + { return MEMCACHED_SUCCESS; + } if (live_servers > ptr->ketama.continuum_count) { @@ -320,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); @@ -373,7 +378,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv list[x].port, list[x].weight, list[x].type); if (not instance) { - return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE); + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } if (list[x].weight > 1) @@ -443,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); @@ -457,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);