X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcached%2Fhosts.cc;h=af61ce2c029419ff8a624568d844c6635dad5828;hb=fe2201f42134ac811614d74f1d79a1a47d4f1317;hp=8afbdb259f5c84114299d643a69cb57742fe5abb;hpb=c8a5aecba8e189092266f304ca81ab42625edf60;p=awesomized%2Flibmemcached diff --git a/src/libmemcached/hosts.cc b/src/libmemcached/hosts.cc index 8afbdb25..af61ce2c 100644 --- a/src/libmemcached/hosts.cc +++ b/src/libmemcached/hosts.cc @@ -1,6 +1,6 @@ /* +--------------------------------------------------------------------+ - | libmemcached - C/C++ Client Library for memcached | + | libmemcached-awesome - C/C++ Client Library for memcached | +--------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted under the terms of the BSD license. | @@ -9,15 +9,16 @@ | the terms online at: https://opensource.org/licenses/BSD-3-Clause | +--------------------------------------------------------------------+ | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | - | Copyright (c) 2020 Michael Wallner | + | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ | +--------------------------------------------------------------------+ */ #include "libmemcached/common.h" #include "libmemcached/assert.hpp" +#include "p9y/gettimeofday.hpp" +#include "p9y/random.hpp" #include -#include /* Protoypes (static) */ static memcached_return_t update_continuum(Memcached *ptr); @@ -51,15 +52,20 @@ memcached_return_t run_distribution(Memcached *ptr) { case MEMCACHED_DISTRIBUTION_CONSISTENT: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: - case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: return update_continuum(ptr); + case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: + return update_continuum(ptr); case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: - case MEMCACHED_DISTRIBUTION_MODULA: break; + case MEMCACHED_DISTRIBUTION_MODULA: + break; - case MEMCACHED_DISTRIBUTION_RANDOM: srandom((uint32_t) time(NULL)); break; + case MEMCACHED_DISTRIBUTION_RANDOM: + srandom((uint32_t) time(NULL)); + break; case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: - default: assert_msg(0, "Invalid distribution type passed to run_distribution()"); + default: + assert_msg(0, "Invalid distribution type passed to run_distribution()"); } return MEMCACHED_SUCCESS; @@ -305,7 +311,7 @@ static memcached_return_t server_add(Memcached *memc, const memcached_string_t & memcached_instance_st *instance = memcached_instance_fetch(memc, memcached_server_count(memc) - 1); - if (__instance_create_with(memc, instance, hostname, port, weight, type) == NULL) { + if (instance_create_with(memc, instance, hostname, port, weight, type) == NULL) { return memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } @@ -340,15 +346,14 @@ memcached_return_t memcached_server_push(memcached_st *shell, const memcached_se ptr->state.is_parsing = true; for (uint32_t x = 0; x < count; ++x, ++original_host_size) { - WATCHPOINT_ASSERT(list[x].hostname[0] != 0); + WATCHPOINT_ASSERT(list[x].hostname[0]); // We have extended the array, and now we will find it, and use it. memcached_instance_st *instance = memcached_instance_fetch(ptr, original_host_size); WATCHPOINT_ASSERT(instance); memcached_string_t hostname = {memcached_string_make_from_cstr(list[x].hostname)}; - if (__instance_create_with(ptr, instance, hostname, list[x].port, list[x].weight, - list[x].type) + if (instance_create_with(ptr, instance, hostname, list[x].port, list[x].weight, list[x].type) == NULL) { ptr->state.is_parsing = false; @@ -391,15 +396,14 @@ memcached_return_t memcached_instance_push(memcached_st *ptr, // We use original_host_size since size will now point to the first new // instance allocated. for (uint32_t x = 0; x < number_of_hosts; ++x, ++original_host_size) { - WATCHPOINT_ASSERT(list[x]._hostname[0] != 0); + WATCHPOINT_ASSERT(list[x]._hostname[0]); // We have extended the array, and now we will find it, and use it. memcached_instance_st *instance = memcached_instance_fetch(ptr, original_host_size); WATCHPOINT_ASSERT(instance); memcached_string_t hostname = {memcached_string_make_from_cstr(list[x]._hostname)}; - if (__instance_create_with(ptr, instance, hostname, list[x].port(), list[x].weight, - list[x].type) + if (instance_create_with(ptr, instance, hostname, list[x].port(), list[x].weight, list[x].type) == NULL) { ptr->state.is_parsing = false;