From: Brian Aker Date: Thu, 14 Jan 2010 05:58:37 +0000 (-0800) Subject: Remove custom parser/use API for parsing in memslap X-Git-Tag: 0.40~114 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f6f52e084fd6329fdf1e004f98f6579485f6038b;p=awesomized%2Flibmemcached Remove custom parser/use API for parsing in memslap --- diff --git a/clients/ms_setting.c b/clients/ms_setting.c index d269e330..95af535c 100644 --- a/clients/ms_setting.c +++ b/clients/ms_setting.c @@ -11,6 +11,8 @@ #include "config.h" +#include + #include #include #include @@ -155,60 +157,28 @@ static ssize_t getline (char **line, size_t *line_size, FILE *fp) */ static void ms_get_serverlist(char *str) { - char *string; - int64_t port; - char *begin_ptr; - char *end_ptr= str + strlen(str); ms_mcd_server_t *srvs= NULL; - char buffer[512]; - char *ptr= NULL; /** * Servers list format is like this. For example: * "localhost:11108, localhost:11109" */ - for (begin_ptr= str, string= index(str, ','); - begin_ptr != end_ptr; - string= index(begin_ptr, ',')) - { - port= 0; - - if (string) - { - memcpy(buffer, begin_ptr, (size_t)(string - begin_ptr)); - buffer[(unsigned int)(string - begin_ptr)]= '\0'; - begin_ptr= string + 1; - } - else - { - size_t length= strlen(begin_ptr); - memcpy(buffer, begin_ptr, length); - buffer[length]= '\0'; - begin_ptr= end_ptr; - } - - ptr= index(buffer, ':'); - - if (ptr != NULL) - { - ptr[0]= '\0'; - ptr++; - port= strtol(ptr, (char **)NULL, 10); - } + memcached_server_st *server_pool; + server_pool = memcached_servers_parse(str); + for (uint32_t loop= 0; loop < memcached_server_list_count(server_pool); loop++) + { assert(ms_setting.srv_cnt < ms_setting.total_srv_cnt); - strcpy(ms_setting.servers[ms_setting.srv_cnt].srv_host_name, buffer); - ms_setting.servers[ms_setting.srv_cnt].srv_port= (int)port; + strcpy(ms_setting.servers[ms_setting.srv_cnt].srv_host_name, server_pool[loop].hostname); + ms_setting.servers[ms_setting.srv_cnt].srv_port= server_pool[loop].port; ms_setting.servers[ms_setting.srv_cnt].disconn_cnt= 0; ms_setting.servers[ms_setting.srv_cnt].reconn_cnt= 0; ms_setting.srv_cnt++; if (ms_setting.srv_cnt >= ms_setting.total_srv_cnt) { - srvs= (ms_mcd_server_t *)realloc( - ms_setting.servers, - (size_t)ms_setting.total_srv_cnt - * sizeof(ms_mcd_server_t) * 2); + srvs= (ms_mcd_server_t *)realloc( ms_setting.servers, + (size_t)ms_setting.total_srv_cnt * sizeof(ms_mcd_server_t) * 2); if (srvs == NULL) { fprintf(stderr, "Can't reallocate servers structure.\n"); @@ -217,10 +187,9 @@ static void ms_get_serverlist(char *str) ms_setting.servers= srvs; ms_setting.total_srv_cnt*= 2; } - - if (isspace(*begin_ptr)) - begin_ptr++; } + + memcached_server_free(server_pool); } /* ms_get_serverlist */ diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 6916a32c..d51d3ad7 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -96,9 +96,7 @@ test_return_t world_flush(libmemcached_test_container_st *container) test_return_t world_pre_run(libmemcached_test_container_st *container) { - uint32_t loop; - - for (loop= 0; loop < memcached_server_list_count(container->construct.servers); loop++) + for (uint32_t loop= 0; loop < memcached_server_list_count(container->construct.servers); loop++) { memcached_server_st *instance= memcached_server_instance_fetch(container->memc, loop); diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 804227fc..6e8a1ce0 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -2892,7 +2892,7 @@ static test_return_t auto_eject_hosts(memcached_st *trash) instance->next_retry = time(NULL) + 15; memc->next_distribution_rebuild= time(NULL) - 1; - for (int x= 0; x < 99; x++) + for (size_t x= 0; x < 99; x++) { uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); test_truth(server_idx != 2); @@ -2903,7 +2903,7 @@ static test_return_t auto_eject_hosts(memcached_st *trash) memc->next_distribution_rebuild= time(NULL) - 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, memc->distribution); - for (int x= 0; x < 99; x++) + for (size_t x= 0; x < 99; x++) { uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); // We re-use instance from above.