From aeb06adc2d73bd2e481c162e3ac162f93a006382 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 26 Jul 2011 12:06:05 -0700 Subject: [PATCH] Update for Lion, error messages. --- clients/memparse.cc | 2 +- libmemcached/connect.cc | 5 ++ libmemcached/csl/common.h | 41 +++++++++ libmemcached/csl/context.cc | 103 +++++++++++++++++++++ libmemcached/csl/context.h | 40 ++------- libmemcached/csl/include.am | 2 + libmemcached/csl/parser.cc | 172 +++++++++++++++++++----------------- libmemcached/csl/parser.yy | 24 +++-- libmemcached/csl/scanner.cc | 84 +++++++++--------- libmemcached/csl/scanner.h | 2 +- libmemcached/csl/scanner.l | 96 ++++++++++---------- libmemcached/csl/server.h | 11 --- libmemcached/error.cc | 20 +++++ libmemcached/error.h | 8 +- libmemcached/error.hpp | 9 +- 15 files changed, 391 insertions(+), 228 deletions(-) create mode 100644 libmemcached/csl/common.h create mode 100644 libmemcached/csl/context.cc diff --git a/clients/memparse.cc b/clients/memparse.cc index 2c80fcd5..4576b7a0 100644 --- a/clients/memparse.cc +++ b/clients/memparse.cc @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { std::cerr << "Failed to parse argument #" << x << " " << argv[x] << std::endl; - std::cerr << "Error message from parser was:\t" << buffer << std::endl; + std::cerr << buffer << std::endl; return EXIT_FAILURE; } } diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 7044306e..8727b289 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -626,6 +626,11 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr) ptr->server_failure_counter= 0; ptr->next_retry= 0; } + else if (memcached_has_current_error(*ptr)) + { + ptr->server_failure_counter++; + set_last_disconnected_host(ptr); + } else { memcached_set_error(*ptr, rc, MEMCACHED_AT); diff --git a/libmemcached/csl/common.h b/libmemcached/csl/common.h new file mode 100644 index 00000000..9c39bb0d --- /dev/null +++ b/libmemcached/csl/common.h @@ -0,0 +1,41 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Configure Scripting Language + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#include + diff --git a/libmemcached/csl/context.cc b/libmemcached/csl/context.cc new file mode 100644 index 00000000..1a60fede --- /dev/null +++ b/libmemcached/csl/context.cc @@ -0,0 +1,103 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Configure Scripting Language + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +void Context::abort(const char *error_arg, yytokentype last_token, const char *last_token_str) +{ + rc= MEMCACHED_PARSE_ERROR; + (void)last_token; + (void)last_token_str; + + if (error_arg) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured while parsing: %s", error_arg); + return; + } + + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured while parsing: %s", memcached_strerror(NULL, MEMCACHED_PARSE_ERROR)); +} + +void Context::error(const char *error_arg, yytokentype last_token, const char *last_token_str) +{ + rc= MEMCACHED_PARSE_ERROR; + if (not error_arg) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Unknown error occured during parsing (%s)", last_token_str ? last_token_str : " "); + return; + } + + if (error_arg and strcmp(error_arg, "memory exhausted") == 0) + { + (void)memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_string_make_from_cstr(error_arg)); + return; + } + + // We now test if it is something other then a syntax error, if it we + // return a generic message + if (error_arg and strcmp(error_arg, "syntax error") == 0) + { } + else if (error_arg) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured during parsing (%s)", error_arg); + return; + } + + if (last_token == UNKNOWN_OPTION and begin) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Unknown option: %s", begin); + } + else if (last_token == UNKNOWN) + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured durring parsing, an unknown token was found."); + } + else + { + memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured while parsing (%s)", last_token_str ? last_token_str : " "); + } +} + +const char *Context::set_hostname(const char *str, size_t size) +{ + size_t copy_length= size_t(NI_MAXHOST) > size ? size : size_t(NI_MAXHOST); + memcpy(_hostname, str, copy_length); + _hostname[copy_length]= 0; + + return _hostname; +} + diff --git a/libmemcached/csl/context.h b/libmemcached/csl/context.h index ce7b0316..94f68134 100644 --- a/libmemcached/csl/context.h +++ b/libmemcached/csl/context.h @@ -37,13 +37,15 @@ #pragma once -#include +#include +#include class Context { public: Context(const char *option_string, size_t option_string_length, memcached_st *memc_arg, memcached_return_t &rc_arg) : + previous_token(END), scanner(NULL), begin(NULL), pos(0), @@ -88,50 +90,22 @@ public: return _is_server; } - const char *set_hostname(const char *str, size_t size) - { - size_t copy_length= (size_t)NI_MAXHOST > size ? size : (size_t)NI_MAXHOST; - memcpy(_hostname, str, copy_length); - _hostname[copy_length]= 0; - - return _hostname; - } + const char *set_hostname(const char *str, size_t size); const char *hostname() { return _hostname; } - void abort(const char *error) - { - if (rc == MEMCACHED_SUCCESS) - rc= MEMCACHED_PARSE_ERROR; - - memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024); - memcached_string_append(error_string, memcached_literal_param("Error occured while parsing: ")); - memcached_string_append(error_string, memcached_string_make_from_cstr(begin)); - memcached_string_append(error_string, memcached_literal_param(" (")); - - if (rc == MEMCACHED_PARSE_ERROR and error) - { - memcached_string_append(error_string, memcached_string_make_from_cstr(error)); - } - else - { - memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, rc))); - } - memcached_string_append(error_string, memcached_literal_param(")")); - - memcached_set_error(*memc, rc, MEMCACHED_AT, memcached_string_value(error_string), memcached_string_length(error_string)); - - memcached_string_free(error_string); - } + void abort(const char *, yytokentype, const char *); + void error(const char *, yytokentype, const char* ); ~Context() { destroy_scanner(); } + yytokentype previous_token; void *scanner; const char *buf; const char *begin; diff --git a/libmemcached/csl/include.am b/libmemcached/csl/include.am index 3081b3f3..427e918c 100644 --- a/libmemcached/csl/include.am +++ b/libmemcached/csl/include.am @@ -6,6 +6,7 @@ DISTCLEANFILES+= \ libmemcached/csl/parser.output noinst_HEADERS+= \ + libmemcached/csl/common.h \ libmemcached/csl/context.h \ libmemcached/csl/parser.h \ libmemcached/csl/scanner.h \ @@ -13,6 +14,7 @@ noinst_HEADERS+= \ libmemcached/csl/symbol.h libmemcached_libmemcached_la_SOURCES+= \ + libmemcached/csl/context.cc \ libmemcached/csl/parser.cc \ libmemcached/csl/scanner.cc diff --git a/libmemcached/csl/parser.cc b/libmemcached/csl/parser.cc index 40e8263e..5bcfac1e 100644 --- a/libmemcached/csl/parser.cc +++ b/libmemcached/csl/parser.cc @@ -78,31 +78,43 @@ #line 36 "libmemcached/csl/parser.yy" -#include +#include #include #include #include #include -#include - #pragma GCC diagnostic ignored "-Wold-style-cast" int conf_lex(YYSTYPE* lvalp, void* scanner); -#define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0) +#define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar + +#define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : "" -inline void config_error(Context *context, yyscan_t *scanner, const char *error) +#define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0) + +// This is bison calling error. +inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str) { if (not context->end()) - context->abort(error); + { + context->error(error, yytokentype(last_token), last_token_str); + } + else + { + context->error(error, yytokentype(last_token), last_token_str); + } } +#define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0) + + /* Line 189 of yacc.c */ -#line 106 "libmemcached/csl/parser.cc" +#line 118 "libmemcached/csl/parser.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -214,7 +226,7 @@ inline void config_error(Context *context, yyscan_t *scanner, const char *error) /* Line 264 of yacc.c */ -#line 218 "libmemcached/csl/parser.cc" +#line 230 "libmemcached/csl/parser.cc" #ifdef short # undef short @@ -523,13 +535,13 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 158, 158, 159, 163, 165, 167, 169, 174, 179, - 183, 187, 198, 206, 214, 221, 225, 229, 233, 237, - 244, 251, 262, 269, 276, 283, 289, 293, 297, 301, - 305, 309, 313, 317, 321, 325, 329, 333, 340, 344, - 348, 352, 356, 360, 364, 368, 372, 376, 380, 384, - 391, 392, 397, 398, 403, 407, 411, 415, 419, 423, - 427, 431, 435, 442, 446, 453, 457, 461 + 0, 170, 170, 171, 175, 177, 179, 181, 186, 191, + 195, 199, 210, 218, 226, 233, 237, 241, 245, 249, + 256, 263, 274, 281, 288, 295, 301, 305, 309, 313, + 317, 321, 325, 329, 333, 337, 341, 345, 352, 356, + 360, 364, 368, 372, 376, 380, 384, 388, 392, 396, + 403, 404, 409, 410, 415, 419, 423, 427, 431, 435, + 439, 443, 447, 454, 458, 465, 469, 473 }; #endif @@ -1521,28 +1533,28 @@ yyreduce: case 4: /* Line 1464 of yacc.c */ -#line 164 "libmemcached/csl/parser.yy" +#line 176 "libmemcached/csl/parser.yy" { ;} break; case 5: /* Line 1464 of yacc.c */ -#line 166 "libmemcached/csl/parser.yy" +#line 178 "libmemcached/csl/parser.yy" { ;} break; case 6: /* Line 1464 of yacc.c */ -#line 168 "libmemcached/csl/parser.yy" +#line 180 "libmemcached/csl/parser.yy" { ;} break; case 7: /* Line 1464 of yacc.c */ -#line 170 "libmemcached/csl/parser.yy" +#line 182 "libmemcached/csl/parser.yy" { context->set_end(); YYACCEPT; @@ -1552,7 +1564,7 @@ yyreduce: case 8: /* Line 1464 of yacc.c */ -#line 175 "libmemcached/csl/parser.yy" +#line 187 "libmemcached/csl/parser.yy" { context->rc= MEMCACHED_PARSE_USER_ERROR; parser_abort(context, NULL); @@ -1562,7 +1574,7 @@ yyreduce: case 9: /* Line 1464 of yacc.c */ -#line 180 "libmemcached/csl/parser.yy" +#line 192 "libmemcached/csl/parser.yy" { memcached_reset(context->memc); ;} @@ -1571,7 +1583,7 @@ yyreduce: case 10: /* Line 1464 of yacc.c */ -#line 184 "libmemcached/csl/parser.yy" +#line 196 "libmemcached/csl/parser.yy" { yydebug= 1; ;} @@ -1580,7 +1592,7 @@ yyreduce: case 11: /* Line 1464 of yacc.c */ -#line 188 "libmemcached/csl/parser.yy" +#line 200 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_parse_configure_file(*context->memc, (yyvsp[(3) - (3)].string).c_str, (yyvsp[(3) - (3)].string).size)) != MEMCACHED_SUCCESS) { @@ -1592,7 +1604,7 @@ yyreduce: case 12: /* Line 1464 of yacc.c */ -#line 199 "libmemcached/csl/parser.yy" +#line 211 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number)))) { @@ -1605,7 +1617,7 @@ yyreduce: case 13: /* Line 1464 of yacc.c */ -#line 207 "libmemcached/csl/parser.yy" +#line 219 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, (yyvsp[(2) - (4)].server).c_str, (yyvsp[(3) - (4)].number), (yyvsp[(4) - (4)].number)))) { @@ -1618,7 +1630,7 @@ yyreduce: case 14: /* Line 1464 of yacc.c */ -#line 215 "libmemcached/csl/parser.yy" +#line 227 "libmemcached/csl/parser.yy" { if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, (yyvsp[(2) - (3)].string).c_str, (yyvsp[(3) - (3)].number)))) { @@ -1630,7 +1642,7 @@ yyreduce: case 15: /* Line 1464 of yacc.c */ -#line 222 "libmemcached/csl/parser.yy" +#line 234 "libmemcached/csl/parser.yy" { memcached_set_configuration_file(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size); ;} @@ -1639,7 +1651,7 @@ yyreduce: case 16: /* Line 1464 of yacc.c */ -#line 226 "libmemcached/csl/parser.yy" +#line 238 "libmemcached/csl/parser.yy" { context->memc->configure.initial_pool_size= (yyvsp[(2) - (2)].number); ;} @@ -1648,7 +1660,7 @@ yyreduce: case 17: /* Line 1464 of yacc.c */ -#line 230 "libmemcached/csl/parser.yy" +#line 242 "libmemcached/csl/parser.yy" { context->memc->configure.max_pool_size= (yyvsp[(2) - (2)].number); ;} @@ -1657,7 +1669,7 @@ yyreduce: case 19: /* Line 1464 of yacc.c */ -#line 238 "libmemcached/csl/parser.yy" +#line 250 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_set_namespace(context->memc, (yyvsp[(2) - (2)].string).c_str, (yyvsp[(2) - (2)].string).size)) != MEMCACHED_SUCCESS) { @@ -1669,7 +1681,7 @@ yyreduce: case 20: /* Line 1464 of yacc.c */ -#line 245 "libmemcached/csl/parser.yy" +#line 257 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (2)].distribution))) != MEMCACHED_SUCCESS) { @@ -1681,7 +1693,7 @@ yyreduce: case 21: /* Line 1464 of yacc.c */ -#line 252 "libmemcached/csl/parser.yy" +#line 264 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, (yyvsp[(2) - (4)].distribution))) != MEMCACHED_SUCCESS) { @@ -1697,7 +1709,7 @@ yyreduce: case 22: /* Line 1464 of yacc.c */ -#line 263 "libmemcached/csl/parser.yy" +#line 275 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, (yyvsp[(2) - (2)].hash))) != MEMCACHED_SUCCESS) { @@ -1709,7 +1721,7 @@ yyreduce: case 23: /* Line 1464 of yacc.c */ -#line 270 "libmemcached/csl/parser.yy" +#line 282 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (2)].behavior), (yyvsp[(2) - (2)].number))) != MEMCACHED_SUCCESS) { @@ -1721,7 +1733,7 @@ yyreduce: case 24: /* Line 1464 of yacc.c */ -#line 277 "libmemcached/csl/parser.yy" +#line 289 "libmemcached/csl/parser.yy" { if ((context->rc= memcached_behavior_set(context->memc, (yyvsp[(1) - (1)].behavior), true)) != MEMCACHED_SUCCESS) { @@ -1733,7 +1745,7 @@ yyreduce: case 25: /* Line 1464 of yacc.c */ -#line 284 "libmemcached/csl/parser.yy" +#line 296 "libmemcached/csl/parser.yy" { ;} break; @@ -1741,7 +1753,7 @@ yyreduce: case 26: /* Line 1464 of yacc.c */ -#line 290 "libmemcached/csl/parser.yy" +#line 302 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS; ;} @@ -1750,7 +1762,7 @@ yyreduce: case 27: /* Line 1464 of yacc.c */ -#line 294 "libmemcached/csl/parser.yy" +#line 306 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT; ;} @@ -1759,7 +1771,7 @@ yyreduce: case 28: /* Line 1464 of yacc.c */ -#line 298 "libmemcached/csl/parser.yy" +#line 310 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK; ;} @@ -1768,7 +1780,7 @@ yyreduce: case 29: /* Line 1464 of yacc.c */ -#line 302 "libmemcached/csl/parser.yy" +#line 314 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK; ;} @@ -1777,7 +1789,7 @@ yyreduce: case 30: /* Line 1464 of yacc.c */ -#line 306 "libmemcached/csl/parser.yy" +#line 318 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH; ;} @@ -1786,7 +1798,7 @@ yyreduce: case 31: /* Line 1464 of yacc.c */ -#line 310 "libmemcached/csl/parser.yy" +#line 322 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS; ;} @@ -1795,7 +1807,7 @@ yyreduce: case 32: /* Line 1464 of yacc.c */ -#line 314 "libmemcached/csl/parser.yy" +#line 326 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_POLL_TIMEOUT; ;} @@ -1804,7 +1816,7 @@ yyreduce: case 33: /* Line 1464 of yacc.c */ -#line 318 "libmemcached/csl/parser.yy" +#line 330 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RCV_TIMEOUT; ;} @@ -1813,7 +1825,7 @@ yyreduce: case 34: /* Line 1464 of yacc.c */ -#line 322 "libmemcached/csl/parser.yy" +#line 334 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT; ;} @@ -1822,7 +1834,7 @@ yyreduce: case 35: /* Line 1464 of yacc.c */ -#line 326 "libmemcached/csl/parser.yy" +#line 338 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SND_TIMEOUT; ;} @@ -1831,7 +1843,7 @@ yyreduce: case 36: /* Line 1464 of yacc.c */ -#line 330 "libmemcached/csl/parser.yy" +#line 342 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE; ;} @@ -1840,7 +1852,7 @@ yyreduce: case 37: /* Line 1464 of yacc.c */ -#line 334 "libmemcached/csl/parser.yy" +#line 346 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE; ;} @@ -1849,7 +1861,7 @@ yyreduce: case 38: /* Line 1464 of yacc.c */ -#line 341 "libmemcached/csl/parser.yy" +#line 353 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL; ;} @@ -1858,7 +1870,7 @@ yyreduce: case 39: /* Line 1464 of yacc.c */ -#line 345 "libmemcached/csl/parser.yy" +#line 357 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS; ;} @@ -1867,7 +1879,7 @@ yyreduce: case 40: /* Line 1464 of yacc.c */ -#line 349 "libmemcached/csl/parser.yy" +#line 361 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; ;} @@ -1876,7 +1888,7 @@ yyreduce: case 41: /* Line 1464 of yacc.c */ -#line 353 "libmemcached/csl/parser.yy" +#line 365 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_NOREPLY; ;} @@ -1885,7 +1897,7 @@ yyreduce: case 42: /* Line 1464 of yacc.c */ -#line 357 "libmemcached/csl/parser.yy" +#line 369 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ; ;} @@ -1894,7 +1906,7 @@ yyreduce: case 43: /* Line 1464 of yacc.c */ -#line 361 "libmemcached/csl/parser.yy" +#line 373 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SORT_HOSTS; ;} @@ -1903,7 +1915,7 @@ yyreduce: case 44: /* Line 1464 of yacc.c */ -#line 365 "libmemcached/csl/parser.yy" +#line 377 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_SUPPORT_CAS; ;} @@ -1912,7 +1924,7 @@ yyreduce: case 45: /* Line 1464 of yacc.c */ -#line 369 "libmemcached/csl/parser.yy" +#line 381 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_NODELAY; ;} @@ -1921,7 +1933,7 @@ yyreduce: case 46: /* Line 1464 of yacc.c */ -#line 373 "libmemcached/csl/parser.yy" +#line 385 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE; ;} @@ -1930,7 +1942,7 @@ yyreduce: case 47: /* Line 1464 of yacc.c */ -#line 377 "libmemcached/csl/parser.yy" +#line 389 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE; ;} @@ -1939,7 +1951,7 @@ yyreduce: case 48: /* Line 1464 of yacc.c */ -#line 381 "libmemcached/csl/parser.yy" +#line 393 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_USE_UDP; ;} @@ -1948,7 +1960,7 @@ yyreduce: case 49: /* Line 1464 of yacc.c */ -#line 385 "libmemcached/csl/parser.yy" +#line 397 "libmemcached/csl/parser.yy" { (yyval.behavior)= MEMCACHED_BEHAVIOR_VERIFY_KEY; ;} @@ -1957,35 +1969,35 @@ yyreduce: case 50: /* Line 1464 of yacc.c */ -#line 391 "libmemcached/csl/parser.yy" +#line 403 "libmemcached/csl/parser.yy" { (yyval.number)= MEMCACHED_DEFAULT_PORT;;} break; case 51: /* Line 1464 of yacc.c */ -#line 393 "libmemcached/csl/parser.yy" +#line 405 "libmemcached/csl/parser.yy" { ;} break; case 52: /* Line 1464 of yacc.c */ -#line 397 "libmemcached/csl/parser.yy" +#line 409 "libmemcached/csl/parser.yy" { (yyval.number)= 1; ;} break; case 53: /* Line 1464 of yacc.c */ -#line 399 "libmemcached/csl/parser.yy" +#line 411 "libmemcached/csl/parser.yy" { ;} break; case 54: /* Line 1464 of yacc.c */ -#line 404 "libmemcached/csl/parser.yy" +#line 416 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_MD5; ;} @@ -1994,7 +2006,7 @@ yyreduce: case 55: /* Line 1464 of yacc.c */ -#line 408 "libmemcached/csl/parser.yy" +#line 420 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_CRC; ;} @@ -2003,7 +2015,7 @@ yyreduce: case 56: /* Line 1464 of yacc.c */ -#line 412 "libmemcached/csl/parser.yy" +#line 424 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1_64; ;} @@ -2012,7 +2024,7 @@ yyreduce: case 57: /* Line 1464 of yacc.c */ -#line 416 "libmemcached/csl/parser.yy" +#line 428 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1A_64; ;} @@ -2021,7 +2033,7 @@ yyreduce: case 58: /* Line 1464 of yacc.c */ -#line 420 "libmemcached/csl/parser.yy" +#line 432 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1_32; ;} @@ -2030,7 +2042,7 @@ yyreduce: case 59: /* Line 1464 of yacc.c */ -#line 424 "libmemcached/csl/parser.yy" +#line 436 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_FNV1A_32; ;} @@ -2039,7 +2051,7 @@ yyreduce: case 60: /* Line 1464 of yacc.c */ -#line 428 "libmemcached/csl/parser.yy" +#line 440 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_HSIEH; ;} @@ -2048,7 +2060,7 @@ yyreduce: case 61: /* Line 1464 of yacc.c */ -#line 432 "libmemcached/csl/parser.yy" +#line 444 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_MURMUR; ;} @@ -2057,7 +2069,7 @@ yyreduce: case 62: /* Line 1464 of yacc.c */ -#line 436 "libmemcached/csl/parser.yy" +#line 448 "libmemcached/csl/parser.yy" { (yyval.hash)= MEMCACHED_HASH_JENKINS; ;} @@ -2066,7 +2078,7 @@ yyreduce: case 63: /* Line 1464 of yacc.c */ -#line 443 "libmemcached/csl/parser.yy" +#line 455 "libmemcached/csl/parser.yy" { (yyval.string)= (yyvsp[(1) - (1)].string); ;} @@ -2075,7 +2087,7 @@ yyreduce: case 64: /* Line 1464 of yacc.c */ -#line 447 "libmemcached/csl/parser.yy" +#line 459 "libmemcached/csl/parser.yy" { (yyval.string)= (yyvsp[(1) - (1)].string); ;} @@ -2084,7 +2096,7 @@ yyreduce: case 65: /* Line 1464 of yacc.c */ -#line 454 "libmemcached/csl/parser.yy" +#line 466 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_CONSISTENT; ;} @@ -2093,7 +2105,7 @@ yyreduce: case 66: /* Line 1464 of yacc.c */ -#line 458 "libmemcached/csl/parser.yy" +#line 470 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_MODULA; ;} @@ -2102,7 +2114,7 @@ yyreduce: case 67: /* Line 1464 of yacc.c */ -#line 462 "libmemcached/csl/parser.yy" +#line 474 "libmemcached/csl/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_RANDOM; ;} @@ -2111,7 +2123,7 @@ yyreduce: /* Line 1464 of yacc.c */ -#line 2115 "libmemcached/csl/parser.cc" +#line 2127 "libmemcached/csl/parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2323,7 +2335,7 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 467 "libmemcached/csl/parser.yy" +#line 479 "libmemcached/csl/parser.yy" void Context::start() diff --git a/libmemcached/csl/parser.yy b/libmemcached/csl/parser.yy index c5eca73e..fd8d0c26 100644 --- a/libmemcached/csl/parser.yy +++ b/libmemcached/csl/parser.yy @@ -35,27 +35,39 @@ %{ -#include +#include #include #include #include #include -#include - #pragma GCC diagnostic ignored "-Wold-style-cast" int conf_lex(YYSTYPE* lvalp, void* scanner); -#define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0) +#define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar + +#define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : "" + +#define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0) -inline void config_error(Context *context, yyscan_t *scanner, const char *error) +// This is bison calling error. +inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str) { if (not context->end()) - context->abort(error); + { + context->error(error, yytokentype(last_token), last_token_str); + } + else + { + context->error(error, yytokentype(last_token), last_token_str); + } } +#define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0) + + %} %token COMMENT diff --git a/libmemcached/csl/scanner.cc b/libmemcached/csl/scanner.cc index 2ff97444..c476019a 100644 --- a/libmemcached/csl/scanner.cc +++ b/libmemcached/csl/scanner.cc @@ -1,7 +1,7 @@ #line 2 "libmemcached/csl/scanner.cc" #line 22 "libmemcached/csl/scanner.l" -#include +#include #include #include #include @@ -1613,207 +1613,207 @@ YY_RULE_SETUP case 7: YY_RULE_SETUP #line 92 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; yyextra->set_server(); return SERVER; } +{ yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; } YY_BREAK case 8: YY_RULE_SETUP #line 94 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SOCKET; } +{ yyextra->begin= yytext; return yyextra->previous_token= SOCKET; } YY_BREAK case 9: YY_RULE_SETUP #line 96 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return BINARY_PROTOCOL; } +{ yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; } YY_BREAK case 10: YY_RULE_SETUP #line 97 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return BUFFER_REQUESTS; } +{ yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; } YY_BREAK case 11: YY_RULE_SETUP #line 98 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return CONFIGURE_FILE; } +{ yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; } YY_BREAK case 12: YY_RULE_SETUP #line 99 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return CONNECT_TIMEOUT; } +{ yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; } YY_BREAK case 13: YY_RULE_SETUP #line 100 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return DISTRIBUTION; } +{ yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; } YY_BREAK case 14: YY_RULE_SETUP #line 101 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return HASH_WITH_NAMESPACE; } +{ yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; } YY_BREAK case 15: YY_RULE_SETUP #line 102 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return HASH; } +{ yyextra->begin= yytext; return yyextra->previous_token= HASH; } YY_BREAK case 16: YY_RULE_SETUP #line 103 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return IO_BYTES_WATERMARK; } +{ yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; } YY_BREAK case 17: YY_RULE_SETUP #line 104 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return IO_KEY_PREFETCH; } +{ yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; } YY_BREAK case 18: YY_RULE_SETUP #line 105 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return IO_MSG_WATERMARK; } +{ yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; } YY_BREAK case 19: YY_RULE_SETUP #line 106 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return NOREPLY; } +{ yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; } YY_BREAK case 20: YY_RULE_SETUP #line 107 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return NUMBER_OF_REPLICAS; } +{ yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; } YY_BREAK case 21: YY_RULE_SETUP #line 108 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return POLL_TIMEOUT; } +{ yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; } YY_BREAK case 22: YY_RULE_SETUP #line 109 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; } +{ yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; } YY_BREAK case 23: YY_RULE_SETUP #line 110 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return RCV_TIMEOUT; } +{ yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; } YY_BREAK case 24: YY_RULE_SETUP #line 111 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; } +{ yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; } YY_BREAK case 25: YY_RULE_SETUP #line 112 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return RETRY_TIMEOUT; } +{ yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; } YY_BREAK case 26: YY_RULE_SETUP #line 113 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SND_TIMEOUT; } +{ yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; } YY_BREAK case 27: YY_RULE_SETUP #line 114 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SOCKET_RECV_SIZE; } +{ yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; } YY_BREAK case 28: YY_RULE_SETUP #line 115 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SOCKET_SEND_SIZE; } +{ yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; } YY_BREAK case 29: YY_RULE_SETUP #line 116 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SORT_HOSTS; } +{ yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; } YY_BREAK case 30: YY_RULE_SETUP #line 117 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SUPPORT_CAS; } +{ yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; } YY_BREAK case 31: YY_RULE_SETUP #line 118 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return _TCP_KEEPALIVE; } +{ yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; } YY_BREAK case 32: YY_RULE_SETUP #line 119 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return _TCP_KEEPIDLE; } +{ yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; } YY_BREAK case 33: YY_RULE_SETUP #line 120 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return _TCP_NODELAY; } +{ yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; } YY_BREAK case 34: YY_RULE_SETUP #line 121 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return USE_UDP; } +{ yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; } YY_BREAK case 35: YY_RULE_SETUP #line 122 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return USER_DATA; } +{ yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; } YY_BREAK case 36: YY_RULE_SETUP #line 123 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return VERIFY_KEY; } +{ yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; } YY_BREAK case 37: YY_RULE_SETUP #line 125 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return POOL_MIN; } +{ yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; } YY_BREAK case 38: YY_RULE_SETUP #line 126 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return POOL_MAX; } +{ yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; } YY_BREAK case 39: YY_RULE_SETUP #line 128 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return NAMESPACE; } +{ yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; } YY_BREAK case 40: YY_RULE_SETUP #line 130 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return INCLUDE; } +{ yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; } YY_BREAK case 41: YY_RULE_SETUP #line 131 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return RESET; } +{ yyextra->begin= yytext; return yyextra->previous_token= RESET; } YY_BREAK case 42: YY_RULE_SETUP #line 132 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return PARSER_DEBUG; } +{ yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; } YY_BREAK case 43: YY_RULE_SETUP #line 133 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return SERVERS; } +{ yyextra->begin= yytext; return yyextra->previous_token= SERVERS; } YY_BREAK case 44: YY_RULE_SETUP #line 134 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return END; } +{ yyextra->begin= yytext; return yyextra->previous_token= END; } YY_BREAK case 45: YY_RULE_SETUP #line 135 "libmemcached/csl/scanner.l" -{ yyextra->begin= yytext; return ERROR; } +{ yyextra->begin= yytext; return yyextra->previous_token= ERROR; } YY_BREAK case 46: YY_RULE_SETUP #line 137 "libmemcached/csl/scanner.l" -{ return TRUE; } +{ return yyextra->previous_token= TRUE; } YY_BREAK case 47: YY_RULE_SETUP #line 138 "libmemcached/csl/scanner.l" -{ return FALSE; } +{ return yyextra->previous_token= FALSE; } YY_BREAK case 48: YY_RULE_SETUP diff --git a/libmemcached/csl/scanner.h b/libmemcached/csl/scanner.h index 90237d4e..20aba812 100644 --- a/libmemcached/csl/scanner.h +++ b/libmemcached/csl/scanner.h @@ -5,7 +5,7 @@ #line 6 "libmemcached/csl/scanner.h" #line 22 "libmemcached/csl/scanner.l" -#include +#include #include #include #include diff --git a/libmemcached/csl/scanner.l b/libmemcached/csl/scanner.l index 8968b3c6..b52a316c 100644 --- a/libmemcached/csl/scanner.l +++ b/libmemcached/csl/scanner.l @@ -20,7 +20,7 @@ %top{ -#include +#include #include #include #include @@ -89,53 +89,53 @@ return COMMENT; } -"--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; } - -"--SOCKET=" { yyextra->begin= yytext; return SOCKET; } - -"--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; } -"--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; } -"--CONFIGURE-FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; } -"--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; } -"--DISTRIBUTION=" { yyextra->begin= yytext; return DISTRIBUTION; } -"--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return HASH_WITH_NAMESPACE; } -"--HASH=" { yyextra->begin= yytext; return HASH; } -"--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; } -"--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; } -"--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; } -"--NOREPLY" { yyextra->begin= yytext; return NOREPLY; } -"--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; } -"--POLL-TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; } -"--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; } -"--RCV-TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; } -"--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; } -"--RETRY-TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; } -"--SND-TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; } -"--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; } -"--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; } -"--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; } -"--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; } -"--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; } -"--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; } -"--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; } -"--USE-UDP" { yyextra->begin= yytext; return USE_UDP; } -"--USER-DATA" { yyextra->begin= yytext; return USER_DATA; } -"--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; } - -"--POOL-MIN=" { yyextra->begin= yytext; return POOL_MIN; } -"--POOL-MAX=" { yyextra->begin= yytext; return POOL_MAX; } - -"--NAMESPACE=" { yyextra->begin= yytext; return NAMESPACE; } - -INCLUDE { yyextra->begin= yytext; return INCLUDE; } -RESET { yyextra->begin= yytext; return RESET; } -DEBUG { yyextra->begin= yytext; return PARSER_DEBUG; } -SERVERS { yyextra->begin= yytext; return SERVERS; } -END { yyextra->begin= yytext; return END; } -ERROR { yyextra->begin= yytext; return ERROR; } - -TRUE { return TRUE; } -FALSE { return FALSE; } +"--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; } + +"--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; } + +"--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; } +"--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; } +"--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; } +"--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; } +"--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; } +"--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; } +"--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; } +"--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; } +"--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; } +"--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; } +"--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; } +"--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; } +"--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; } +"--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; } +"--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; } +"--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; } +"--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; } +"--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; } +"--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; } +"--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; } +"--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; } +"--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; } +"--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; } +"--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; } +"--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; } +"--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; } +"--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; } +"--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; } + +"--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; } +"--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; } + +"--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; } + +INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; } +RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; } +DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; } +SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; } +END { yyextra->begin= yytext; return yyextra->previous_token= END; } +ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; } + +TRUE { return yyextra->previous_token= TRUE; } +FALSE { return yyextra->previous_token= FALSE; } "--"[[:alnum:]]* { diff --git a/libmemcached/csl/server.h b/libmemcached/csl/server.h index f78db99b..92f7ed56 100644 --- a/libmemcached/csl/server.h +++ b/libmemcached/csl/server.h @@ -47,14 +47,3 @@ struct server_t const char *c_str; size_t size; }; - -#if 0 -#include -inline std::ostream& operator<<(std::ostream& output, const server_t& arg) -{ - output.write(arg.c_str, arg.size); - output << ':' << arg.port; - output << '+' << arg.weight; - return output; -} -#endif diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 391e67c1..5afb2282 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -36,6 +36,7 @@ */ #include +#include #define MAX_ERROR_LENGTH 2048 struct memcached_error_t @@ -147,6 +148,11 @@ static void _set(memcached_st& memc, memcached_string_t *str, memcached_return_t errmsg_ptr, at); } + else if (rc == MEMCACHED_PARSE_ERROR and str and str->size) + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%.*s -> %s", + int(str->size), str->c_str, at); + } else if (str and str->size) { error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "%s, %.*s -> %s", @@ -189,6 +195,20 @@ memcached_return_t memcached_set_error(memcached_st& memc, memcached_return_t rc return rc; } +memcached_return_t memcached_set_parser_error(memcached_st& memc, + const char *at, + const char *format, ...) +{ + va_list args; + + char buffer[BUFSIZ]; + va_start(args, format); + int length= vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length); +} + memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str) { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); diff --git a/libmemcached/error.h b/libmemcached/error.h index 99beb8ca..8b04e09b 100644 --- a/libmemcached/error.h +++ b/libmemcached/error.h @@ -42,16 +42,16 @@ extern "C" { #endif LIBMEMCACHED_API - const char *memcached_last_error_message(memcached_st *memc); + const char *memcached_last_error_message(memcached_st *); LIBMEMCACHED_API - void memcached_error_print(const memcached_st *self); + void memcached_error_print(const memcached_st *); LIBMEMCACHED_API - memcached_return_t memcached_last_error(memcached_st *memc); + memcached_return_t memcached_last_error(memcached_st *); LIBMEMCACHED_API - int memcached_last_error_errno(memcached_st *memc); + int memcached_last_error_errno(memcached_st *); LIBMEMCACHED_API const char *memcached_server_error(memcached_server_instance_st ptr); diff --git a/libmemcached/error.hpp b/libmemcached/error.hpp index 1eaba13f..252101ac 100644 --- a/libmemcached/error.hpp +++ b/libmemcached/error.hpp @@ -35,16 +35,21 @@ * */ -#pragma once - #include +#pragma once + #ifdef __cplusplus #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define MEMCACHED_AT __FILE__ ":" TOSTRING(__LINE__) +LIBMEMCACHED_LOCAL +memcached_return_t memcached_set_parser_error(memcached_st& memc, + const char *at, + const char *format, ...); + LIBMEMCACHED_LOCAL memcached_return_t memcached_set_error(memcached_st&, memcached_return_t rc, const char *at); -- 2.30.2