From: Brian Aker Date: Tue, 12 Jan 2010 23:42:29 +0000 (-0800) Subject: Final bits of abstraction. X-Git-Tag: 0.40~126 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f76fd606efc52fa6d99424c854dade96b3860bec;p=awesomized%2Flibmemcached Final bits of abstraction. --- diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 27099ac8..fe468f98 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -53,7 +53,7 @@ struct memcached_st { memcached_server_distribution_t distribution; memcached_hash_t hash; uint32_t continuum_points_counter; // Ketama - memcached_server_st *hosts; + memcached_server_st *servers; memcached_server_st *last_disconnected_server; int32_t snd_timeout; int32_t rcv_timeout; @@ -114,7 +114,7 @@ void memcached_servers_reset(memcached_st *ptr); // Local Only Inline static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) { - return &ptr->hosts[server_key]; + return &ptr->servers[server_key]; } /* Public API */ diff --git a/libmemcached/server.h b/libmemcached/server.h index f7531883..1b99ecbb 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -64,8 +64,8 @@ static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, #define memcached_server_count(A) (A)->number_of_hosts #define memcached_server_name(A,B) (B).hostname #define memcached_server_port(A,B) (B).port -#define memcached_server_list(A) (A)->hosts -#define memcached_server_list_set(A,B) (A)->hosts=(B) +#define memcached_server_list(A) (A)->servers +#define memcached_server_list_set(A,B) (A)->servers=(B) #define memcached_server_response_count(A) (A)->cursor_active LIBMEMCACHED_API diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 1c2a80fd..749659f3 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -3517,8 +3517,7 @@ static test_return_t pre_binary(memcached_st *memc) { memcached_return_t rc= MEMCACHED_FAILURE; memcached_st *memc_clone; - memcached_server_instance_st *instance= - memcached_server_instance_fetch(memc, 0); + memcached_server_instance_st *instance; memc_clone= memcached_clone(NULL, memc); test_truth(memc_clone); @@ -3526,6 +3525,8 @@ static test_return_t pre_binary(memcached_st *memc) // will not toggle protocol on an connection. memcached_version(memc_clone); + instance= memcached_server_instance_fetch(memc_clone, 0); + if (instance->major_version >= 1 && instance->minor_version > 2) { rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); @@ -3956,7 +3957,11 @@ static test_return_t noreply_test(memcached_st *memc) */ int no_msg=0; for (uint32_t x=0; x < memcached_server_count(memc); ++x) - no_msg+=(int)(memc->hosts[x].cursor_active); + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, x); + no_msg+=(int)(instance->cursor_active); + } test_truth(no_msg == 0); test_truth(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS); @@ -4235,7 +4240,10 @@ static test_return_t replication_get_test(memcached_st *memc) for (uint32_t host= 0; host < memcached_server_count(memc); ++host) { memcached_st *memc_clone= memcached_clone(NULL, memc); - memc_clone->hosts[host].port= 0; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc_clone, host); + + instance->port= 0; for (int x= 'a'; x <= 'z'; ++x) { @@ -4294,7 +4302,9 @@ static test_return_t replication_mget_test(memcached_st *memc) for (uint32_t host= 0; host < memc_clone->number_of_hosts; host++) { memcached_st *new_clone= memcached_clone(NULL, memc); - new_clone->hosts[host].port= 0; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(new_clone, host); + instance->port= 0; for (int x= 'a'; x <= 'z'; ++x) { @@ -4389,7 +4399,10 @@ static test_return_t replication_delete_test(memcached_st *memc) uint32_t hash= memcached_generate_hash(memc, keys[0], len[0]); for (uint32_t x= 0; x < (repl + 1); ++x) { - memc_clone->hosts[hash].port= 0; + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc_clone, x); + + instance->port= 0; if (++hash == memc_clone->number_of_hosts) hash= 0; } @@ -4435,7 +4448,12 @@ static uint16_t *get_udp_request_ids(memcached_st *memc) unsigned int x; for (x= 0; x < memcached_server_count(memc); x++) - ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[x].write_buffer); + { + memcached_server_instance_st *instance= + memcached_server_instance_fetch(memc, x); + + ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) instance->write_buffer); + } return ids; } @@ -4443,7 +4461,7 @@ static uint16_t *get_udp_request_ids(memcached_st *memc) static test_return_t post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids) { unsigned int x; - memcached_server_st *cur_server = memc->hosts; + memcached_server_st *cur_server = memcached_server_list(memc); uint16_t *cur_req_ids = get_udp_request_ids(memc); for (x= 0; x < memcached_server_count(memc); x++) @@ -4475,16 +4493,24 @@ static test_return_t init_udp(memcached_st *memc) uint32_t num_hosts= memcached_server_count(memc); unsigned int x= 0; memcached_server_st servers[num_hosts]; - memcpy(servers, memc->hosts, sizeof(memcached_server_st) * num_hosts); + memcpy(servers, memcached_server_list(memc), sizeof(memcached_server_st) * num_hosts); for (x= 0; x < num_hosts; x++) - memcached_server_free(&memc->hosts[x]); + { + memcached_server_instance_st *set_instance= + memcached_server_instance_fetch(memc, x); + + memcached_server_free(set_instance); + } memc->number_of_hosts= 0; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1); for (x= 0; x < num_hosts; x++) { + memcached_server_instance_st *set_instance= + memcached_server_instance_fetch(memc, x); + test_truth(memcached_server_add_udp(memc, servers[x].hostname, servers[x].port) == MEMCACHED_SUCCESS); - test_truth(memc->hosts[x].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH); + test_truth(set_instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH); } return TEST_SUCCESS;