From: Brian Aker Date: Sat, 19 Mar 2011 00:57:32 +0000 (-0700) Subject: Final bits for options in parser for behaviors. X-Git-Tag: 0.51~15^2~75^2~18 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=696240873d8c6ca5edc482a7395984aac14d5b32;p=m6w6%2Flibmemcached Final bits for options in parser for behaviors. --- diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index d4275a09..3a7cee2e 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -127,6 +127,8 @@ inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, %type server %type distribution %type hash +%type behavior_boolean +%type behavior_number %% @@ -150,137 +152,152 @@ expression: ; behaviors: - AUTO_EJECT_HOSTS + | DISTRIBUTION '=' distribution { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, 1); + memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); } - | BINARY_PROTOCOL + | HASH '=' hash { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); + memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); } - | BUFFER_REQUESTS + | KETAMA_HASH '=' hash { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1); + memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3); } - | CACHE_LOOKUPS + | behavior_number '=' NUMBER { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, 1); + memcached_behavior_set(parser->memc, $1, $3); } - | CONNECT_TIMEOUT '=' NUMBER + | behavior_boolean { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, $3); + memcached_behavior_set(parser->memc, $1, true); } - | _CORK + | USER_DATA { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CORK, 1); } - | DISTRIBUTION '=' distribution + ; + +behavior_number: + CONNECT_TIMEOUT { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); + $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT; } - | HASH '=' hash + | IO_MSG_WATERMARK { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); + $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK; } - | HASH_WITH_PREFIX_KEY + | IO_BYTES_WATERMARK { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY, 1); + $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK; } - | IO_BYTES_WATERMARK '=' NUMBER + | IO_KEY_PREFETCH { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, $3); + $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH; } - | IO_KEY_PREFETCH '=' NUMBER + | NUMBER_OF_REPLICAS { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, $3); + $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS; } - | IO_MSG_WATERMARK '=' NUMBER + | POLL_TIMEOUT { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, $3); + $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT; } - | KETAMA + | RCV_TIMEOUT { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA, true); + $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT; } - | KETAMA_HASH + | RETRY_TIMEOUT { + $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT; } - | KETAMA_WEIGHTED + | SERVER_FAILURE_LIMIT { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, true); + $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT; } - | NOREPLY + | SND_TIMEOUT { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_NOREPLY, 1); + $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT; } - | NUMBER_OF_REPLICAS '=' NUMBER + | SOCKET_RECV_SIZE { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, $3); + $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE; } - | POLL_TIMEOUT '=' NUMBER + | SOCKET_SEND_SIZE { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, $3); + $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE; } - | RANDOMIZE_REPLICA_READ + ; + +behavior_boolean: + AUTO_EJECT_HOSTS + { + $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS; + } + | BINARY_PROTOCOL + { + $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL; + } + | BUFFER_REQUESTS + { + $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS; + } + | CACHE_LOOKUPS { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, true); + $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS; } - | RCV_TIMEOUT '=' NUMBER + | _CORK { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, $3); + $$= MEMCACHED_BEHAVIOR_CORK; } - | RETRY_TIMEOUT '=' NUMBER + | HASH_WITH_PREFIX_KEY { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, $3); + $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; } - | SERVER_FAILURE_LIMIT '=' NUMBER + | KETAMA { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, $3); + $$= MEMCACHED_BEHAVIOR_KETAMA; } - | SND_TIMEOUT '=' NUMBER + | KETAMA_WEIGHTED { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, $3); + $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED; } - | SOCKET_RECV_SIZE '=' NUMBER + | NOREPLY { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, $3); + $$= MEMCACHED_BEHAVIOR_NOREPLY; } - | SOCKET_SEND_SIZE '=' NUMBER + | RANDOMIZE_REPLICA_READ { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, $3); + $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ; } | SORT_HOSTS { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, true); + $$= MEMCACHED_BEHAVIOR_SORT_HOSTS; } | SUPPORT_CAS { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true); + $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS; } | _TCP_NODELAY { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true); + $$= MEMCACHED_BEHAVIOR_TCP_NODELAY; } | _TCP_KEEPALIVE { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, true); + $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE; } | _TCP_KEEPIDLE { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, true); - } - | USER_DATA - { + $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE; } | USE_UDP { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_USE_UDP, true); + $$= MEMCACHED_BEHAVIOR_USE_UDP; } | VERIFY_KEY { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true); + $$= MEMCACHED_BEHAVIOR_VERIFY_KEY; } - ; + server_list: server diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l index c8c2ea82..1afc50eb 100644 --- a/libmemcached/options/scanner.l +++ b/libmemcached/options/scanner.l @@ -125,6 +125,7 @@ RCV_TIMEOUT { return RCV_TIMEOUT; } RCV-TIMEOUT { return RCV_TIMEOUT; } RETRY_TIMEOUT { return RETRY_TIMEOUT; } RETRY-TIMEOUT { return RETRY_TIMEOUT; } +SERVER_FAILURE_LIMIT { return SERVER_FAILURE_LIMIT; } SERVER-FAILURE-LIMIT { return SERVER_FAILURE_LIMIT; } SND_TIMEOUT { return SND_TIMEOUT; } SND-TIMEOUT { return SND_TIMEOUT; } diff --git a/libmemcached/options/symbol.h b/libmemcached/options/symbol.h index 161474dc..d48a5a29 100644 --- a/libmemcached/options/symbol.h +++ b/libmemcached/options/symbol.h @@ -49,6 +49,7 @@ union YYSTYPE double double_number; memcached_server_distribution_t distribution; memcached_hash_t hash; + memcached_behavior_t behavior; }; typedef union YYSTYPE YYSTYPE; diff --git a/tests/mem_functions.c b/tests/mem_functions.c index ccd4b95b..2cb8cfb9 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -6299,8 +6299,10 @@ test_st error_conditions[] ={ test_st parser_tests[] ={ {"behavior", 0, (test_callback_fn)behavior_parser_test }, + {"boolean_options", 0, (test_callback_fn)parser_boolean_options_test }, {"distribtions", 0, (test_callback_fn)parser_distribution_test }, {"hash", 0, (test_callback_fn)parser_hash_test }, + {"number_options", 0, (test_callback_fn)parser_number_options_test }, {"server", 0, (test_callback_fn)server_test }, {"servers", 0, (test_callback_fn)servers_test }, {0, 0, (test_callback_fn)0} diff --git a/tests/parser.cc b/tests/parser.cc index da3c45d3..3ee37a2c 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -129,6 +129,79 @@ test_return_t servers_test(memcached_st *junk) return TEST_SUCCESS; } +scanner_string_st test_number_options[]= { + { STRING_WITH_LEN("--CONNECT_TIMEOUT=456") }, + { STRING_WITH_LEN("--IO_MSG_WATERMARK=456") }, + { STRING_WITH_LEN("--IO_BYTES_WATERMARK=456") }, + { STRING_WITH_LEN("--IO_KEY_PREFETCH=456") }, + { STRING_WITH_LEN("--NUMBER_OF_REPLICAS=456") }, + { STRING_WITH_LEN("--POLL_TIMEOUT=456") }, + { STRING_WITH_LEN("--RCV_TIMEOUT=456") }, + { STRING_WITH_LEN("--RETRY_TIMEOUT=456") }, + { STRING_WITH_LEN("--SERVER_FAILURE_LIMIT=456") }, + { STRING_WITH_LEN("--SND_TIMEOUT=456") }, + { STRING_WITH_LEN("--SOCKET_RECV_SIZE=456") }, + { STRING_WITH_LEN("--SOCKET_SEND_SIZE=456") }, + { NULL, 0} +}; + +scanner_string_st test_boolean_options[]= { + { STRING_WITH_LEN("--AUTO_EJECT_HOSTS") }, + { STRING_WITH_LEN("--BINARY_PROTOCOL") }, + { STRING_WITH_LEN("--BUFFER_REQUESTS") }, + { STRING_WITH_LEN("--CACHE_LOOKUPS") }, + { STRING_WITH_LEN("--CORK") }, + { STRING_WITH_LEN("--HASH_WITH_PREFIX_KEY") }, + { STRING_WITH_LEN("--KETAMA") }, + { STRING_WITH_LEN("--KETAMA_WEIGHTED") }, + { STRING_WITH_LEN("--NOREPLY") }, + { STRING_WITH_LEN("--RANDOMIZE_REPLICA_READ") }, + { STRING_WITH_LEN("--SORT_HOSTS") }, + { STRING_WITH_LEN("--SUPPORT_CAS") }, + { STRING_WITH_LEN("--TCP_NODELAY") }, + { STRING_WITH_LEN("--TCP_KEEPALIVE") }, + { STRING_WITH_LEN("--TCP_KEEPIDLE") }, + { STRING_WITH_LEN("--USE_UDP") }, + { STRING_WITH_LEN("--VERIFY_KEY") }, + { NULL, 0} +}; + +test_return_t parser_number_options_test(memcached_st *junk) +{ + (void)junk; + memcached_st *memc; + memc= memcached_create(NULL); + + for (scanner_string_st *ptr= test_number_options; ptr->size; ptr++) + { + memcached_return_t rc; + rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size); + test_true_got(rc == MEMCACHED_SUCCESS, ptr->c_ptr); + } + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t parser_boolean_options_test(memcached_st *junk) +{ + (void)junk; + memcached_st *memc; + memc= memcached_create(NULL); + + for (scanner_string_st *ptr= test_boolean_options; ptr->size; ptr++) + { + memcached_return_t rc; + rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size); + test_true_got(rc == MEMCACHED_SUCCESS, ptr->c_ptr); + } + + memcached_free(memc); + + return TEST_SUCCESS; +} + test_return_t behavior_parser_test(memcached_st *junk) { (void)junk; diff --git a/tests/parser.h b/tests/parser.h index 08fe90cf..78518d20 100644 --- a/tests/parser.h +++ b/tests/parser.h @@ -52,12 +52,18 @@ test_return_t servers_test(memcached_st *memc); LIBTEST_INTERNAL_API test_return_t behavior_parser_test(memcached_st *junk); +LIBTEST_INTERNAL_API +test_return_t parser_number_options_test(memcached_st *junk); + LIBTEST_INTERNAL_API test_return_t parser_distribution_test(memcached_st *junk); LIBTEST_INTERNAL_API test_return_t parser_hash_test(memcached_st *junk); +LIBTEST_INTERNAL_API +test_return_t parser_boolean_options_test(memcached_st *junk); + #ifdef __cplusplus } #endif