From: Brian Aker Date: Sat, 9 Jan 2010 22:34:59 +0000 (-0800) Subject: Match count (and sorted .bzignore) X-Git-Tag: 0.37~12 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=249052d14a777267008d473ea8480e7d68e636cd;p=m6w6%2Flibmemcached Match count (and sorted .bzignore) --- diff --git a/.bzrignore b/.bzrignore index 6914a170..9726145e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -43,32 +43,6 @@ docs/*.html docs/pod2htmd.tmp docs/pod2htmi.tmp example/memcached_light -libmemcached-*.tar.gz -libmemcached-0.30-1.src.rpm -libmemcached-0.30-1.x86_64.rpm -libmemcached-0.31-1.src.rpm -libmemcached-0.31-1.x86_64.rpm -libmemcached-?.??/ -libmemcached/memcached_configure.h -libtool -libtool.m4 -ltoptions.m4 -ltsugar.m4 -ltversion.m4 -lt~obsolete.m4 -stamp-h1 -support/Makefile -support/Makefile.in -support/libmemcached-fc.spec -support/libmemcached.pc -support/libmemcached.spec -tests/atomsmasher -tests/output.cmp -tests/startservers -tests/testapp -tests/testhashkit -tests/testplus -tests/udptest hashkit_clone.pop hashkit_crc32.pop hashkit_create.pop @@ -84,56 +58,70 @@ hashkit_jenkins.pop hashkit_md5.pop hashkit_murmur.pop hashkit_value.pop -libmemcached_examples.pop +libmemcached-*.tar.gz +libmemcached-0.30-1.src.rpm +libmemcached-0.30-1.x86_64.rpm +libmemcached-0.31-1.src.rpm +libmemcached-0.31-1.x86_64.rpm +libmemcached-?.??/ libmemcached.pop +libmemcached/configure.h +libmemcached/memcached_configure.h +libmemcached_examples.pop libmemcachedutil.pop -memcached_add_by_key.pop +libtool +libtool.m4 +ltoptions.m4 +ltsugar.m4 +ltversion.m4 +lt~obsolete.m4 memcached_add.pop +memcached_add_by_key.pop memcached_analyze.pop -memcached_append_by_key.pop memcached_append.pop +memcached_append_by_key.pop memcached_behavior_get.pop memcached_behavior_set.pop memcached_callback_get.pop memcached_callback_set.pop -memcached_cas_by_key.pop memcached_cas.pop +memcached_cas_by_key.pop memcached_clone.pop memcached_create.pop memcached_decrement.pop memcached_decrement_with_initial.pop -memcached_delete_by_key.pop memcached_delete.pop +memcached_delete_by_key.pop memcached_dump.pop -memcached_fetch_execute.pop memcached_fetch.pop +memcached_fetch_execute.pop memcached_fetch_result.pop -memcached_flush_buffers.pop memcached_flush.pop +memcached_flush_buffers.pop memcached_free.pop memcached_generate_hash_value.pop +memcached_get.pop memcached_get_by_key.pop memcached_get_memory_allocators.pop -memcached_get.pop memcached_get_user_data.pop memcached_increment.pop memcached_increment_with_initial.pop memcached_lib_version.pop +memcached_mget.pop memcached_mget_by_key.pop -memcached_mget_execute_by_key.pop memcached_mget_execute.pop -memcached_mget.pop +memcached_mget_execute_by_key.pop memcached_pool_behavior_get.pop memcached_pool_behavior_set.pop memcached_pool_create.pop memcached_pool_destroy.pop memcached_pool_pop.pop memcached_pool_push.pop -memcached_prepend_by_key.pop memcached_prepend.pop +memcached_prepend_by_key.pop memcached_quit.pop -memcached_replace_by_key.pop memcached_replace.pop +memcached_replace_by_key.pop memcached_result_cas.pop memcached_result_create.pop memcached_result_flags.pop @@ -146,19 +134,19 @@ memcached_result_value.pop memcached_server_add.pop memcached_server_add_unix_socket.pop memcached_server_count.pop +memcached_server_list.pop memcached_server_list_append.pop memcached_server_list_count.pop memcached_server_list_free.pop -memcached_server_list.pop memcached_server_push.pop memcached_servers_parse.pop +memcached_set.pop memcached_set_by_key.pop memcached_set_memory_allocators.pop -memcached_set.pop memcached_set_user_data.pop +memcached_stat.pop memcached_stat_get_keys.pop memcached_stat_get_value.pop -memcached_stat.pop memcached_stat_servername.pop memcached_strerror.pop memcached_verbosity.pop @@ -172,3 +160,16 @@ memflush.pop memrm.pop memslap.pop memstat.pop +stamp-h1 +support/Makefile +support/Makefile.in +support/libmemcached-fc.spec +support/libmemcached.pc +support/libmemcached.spec +tests/atomsmasher +tests/output.cmp +tests/startservers +tests/testapp +tests/testhashkit +tests/testplus +tests/udptest diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 5ce4b70d..cb231026 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -29,7 +29,7 @@ static void sort_hosts(memcached_st *ptr) if (ptr->number_of_hosts) { qsort(ptr->hosts, ptr->number_of_hosts, sizeof(memcached_server_st), compare_servers); - ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts; + ptr->hosts[0].number_of_hosts= ptr->number_of_hosts; } } @@ -62,12 +62,12 @@ memcached_return_t run_distribution(memcached_st *ptr) void server_list_free(memcached_st *ptr, memcached_server_st *servers) { - unsigned int x; + uint32_t x; if (servers == NULL) return; - for (x= 0; x < servers->count; x++) + for (x= 0; x < memcached_servers_count(servers); x++) if (servers[x].address_info) { freeaddrinfo(servers[x].address_info); @@ -319,7 +319,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st if (!list) return MEMCACHED_SUCCESS; - count= list[0].count; + count= memcached_servers_count(list); new_host_list= ptr->call_realloc(ptr, ptr->hosts, sizeof(memcached_server_st) * (count + ptr->number_of_hosts)); @@ -342,7 +342,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st list[x].port, list[x].weight, list[x].type); ptr->number_of_hosts++; } - ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts; + ptr->hosts[0].number_of_hosts= (uint16_t) ptr->number_of_hosts; return run_distribution(ptr); } @@ -427,7 +427,8 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, /* TODO: Check return type */ (void)memcached_server_create_with(ptr, &ptr->hosts[ptr->number_of_hosts], hostname, port, weight, type); ptr->number_of_hosts++; - ptr->hosts[0].count= (uint16_t) ptr->number_of_hosts; + + memcached_servers_set_count(&ptr->hosts[0], ptr->number_of_hosts); return run_distribution(ptr); } @@ -484,7 +485,7 @@ memcached_server_st *memcached_server_list_append_with_weight(memcached_server_s count= 1; if (ptr != NULL) { - count+= ptr[0].count; + count+= memcached_servers_count(ptr); } new_host_list= (memcached_server_st *)realloc(ptr, sizeof(memcached_server_st) * count); @@ -498,21 +499,8 @@ memcached_server_st *memcached_server_list_append_with_weight(memcached_server_s memcached_server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, MEMCACHED_CONNECTION_TCP); /* Backwards compatibility hack */ - new_host_list[0].count= (uint16_t) count; + memcached_servers_set_count(new_host_list, count); *error= MEMCACHED_SUCCESS; return new_host_list; } - -unsigned int memcached_server_list_count(memcached_server_st *ptr) -{ - if (ptr == NULL) - return 0; - - return ptr[0].count; -} - -void memcached_server_list_free(memcached_server_st *ptr) -{ - server_list_free(NULL, ptr); -} diff --git a/libmemcached/server.c b/libmemcached/server.c index d0ce3f74..8616657c 100644 --- a/libmemcached/server.c +++ b/libmemcached/server.c @@ -177,3 +177,16 @@ memcached_server_st *memcached_server_get_last_disconnect(memcached_st *ptr) { return ptr->last_disconnected_server; } + +uint32_t memcached_server_list_count(memcached_server_st *ptr) +{ + if (ptr == NULL) + return 0; + + return memcached_servers_count(ptr); +} + +void memcached_server_list_free(memcached_server_st *ptr) +{ + server_list_free(NULL, ptr); +} diff --git a/libmemcached/server.h b/libmemcached/server.h index d8e9daa8..73c02876 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -21,7 +21,7 @@ struct memcached_server_st { bool is_allocated:1; bool sockaddr_inited:1; } options; - uint16_t count; + uint32_t number_of_hosts; uint32_t cursor_active; in_port_t port; int cached_errno; @@ -47,6 +47,16 @@ struct memcached_server_st { char hostname[MEMCACHED_MAX_HOST_LENGTH]; }; +static inline uint32_t memcached_servers_count(memcached_server_st *servers) +{ + return servers->number_of_hosts; +} + +static inline uint32_t memcached_servers_set_count(memcached_server_st *servers, uint32_t count) +{ + return servers->number_of_hosts= count; +} + #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 diff --git a/tests/function.c b/tests/function.c index 9ccc4026..3df86f31 100644 --- a/tests/function.c +++ b/tests/function.c @@ -109,7 +109,7 @@ static test_return_t server_sort_test(memcached_st *ptr __attribute__((unused)) test_ports[x]= (uint32_t)random() % 64000; rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); test_truth(local_memc->number_of_hosts == x + 1); - test_truth(local_memc->hosts[0].count == x+1); + test_truth(memcached_servers_count(local_memc->hosts) == x+1); test_truth(rc == MEMCACHED_SUCCESS); } @@ -180,7 +180,7 @@ static test_return_t server_unsort_test(memcached_st *ptr __attribute__((unused test_ports[x]= (uint32_t)(random() % 64000); rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); test_truth(local_memc->number_of_hosts == x+1); - test_truth(local_memc->hosts[0].count == x+1); + test_truth(memcached_servers_count(local_memc->hosts) == x+1); test_truth(rc == MEMCACHED_SUCCESS); }