From 74426b42972cd3bfd9de87debf66a6d65315442c Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 3 May 2011 17:45:03 -0700 Subject: [PATCH] Merge in fix so that we don't have to do weight on the const root --- libmemcached/hosts.cc | 15 ++++++++++++++- libmemcached/server.cc | 5 ----- libmemcached/server_list.cc | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 885a79b7..6a8b660f 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -343,10 +343,16 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv /* TODO check return type */ instance= memcached_server_create_with(ptr, instance, list[x].hostname, list[x].port, list[x].weight, list[x].type); - if (! instance) + if (not instance) { return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE); } + + if (list[x].weight > 1) + { + ptr->ketama.weighted= true; + } + ptr->number_of_hosts++; } @@ -440,7 +446,14 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, /* TODO: Check return type */ instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + (void)memcached_server_create_with(ptr, instance, hostname, port, weight, type); + + if (weight > 1) + { + ptr->ketama.weighted= true; + } + ptr->number_of_hosts++; instance= memcached_server_instance_fetch(ptr, 0); diff --git a/libmemcached/server.cc b/libmemcached/server.cc index 1eb50ee4..02078860 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -51,11 +51,6 @@ static inline void _server_init(memcached_server_st *self, const memcached_st *r self->next_retry= 0; } - if (self->weight > 1 && root) - { - ((memcached_st *)root)->ketama.weighted= true; - } - self->root= root; self->limit_maxbytes= 0; if (hostname == NULL) diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index ca37f7f9..8a76bf39 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -10,7 +10,7 @@ */ -#include "common.h" +#include memcached_server_list_st memcached_server_list_append_with_weight(memcached_server_list_st ptr, -- 2.30.2