From cb08b8d0a35a78bde8a5b4caccab5dd2d789cca3 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 24 Apr 2012 09:13:12 -0700 Subject: [PATCH] Update for protocol (and a single fix). --- example/t/include.am | 1 + libmemcached-1.0/struct/server.h | 2 +- libmemcached/response.cc | 30 +++++++++---------- libtest/test.h | 9 ++++++ m4/bottom.m4 | 14 ++------- memcached/include.am | 6 ++-- memcached/memcached.c | 17 +++++++---- tests/include.am | 1 + tests/libmemcached-1.0/include.am | 6 ++-- tests/libmemcached-1.0/print.cc | 27 +++++++++++++++-- tests/libmemcached-1.0/setup_and_teardowns.cc | 2 ++ tests/print.h | 6 ++++ tests/runner.h | 1 + 13 files changed, 79 insertions(+), 43 deletions(-) diff --git a/example/t/include.am b/example/t/include.am index b9b7556d..212207f4 100644 --- a/example/t/include.am +++ b/example/t/include.am @@ -18,6 +18,7 @@ example_t_memcached_light_LDADD= example_t_memcached_light_SOURCES+= example/t/memcached_light.cc example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/memcached_get.cc +example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/print.cc example_t_memcached_light_SOURCES+= tests/libmemcached-1.0/setup_and_teardowns.cc example_t_memcached_light_CXXFLAGS = $(AM_CXXFLAGS) example_t_memcached_light_DEPENDENCIES= $(MEMCACHED_LIGHT_TESTS_LDADDS) example/memcached_light diff --git a/libmemcached-1.0/struct/server.h b/libmemcached-1.0/struct/server.h index e2be59b8..a1ed7389 100644 --- a/libmemcached-1.0/struct/server.h +++ b/libmemcached-1.0/struct/server.h @@ -85,7 +85,7 @@ struct memcached_server_st { uint32_t timeouts; } io_wait_count; uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set. - uint8_t micro_version; // ditto + uint8_t micro_version; // ditto, and note that this is the third, not second version bit uint8_t minor_version; // ditto memcached_connection_t type; char *read_ptr; diff --git a/libmemcached/response.cc b/libmemcached/response.cc index faf20ff9..4ba85648 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -236,9 +236,9 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta { /* Find the space, and then move one past it to copy version */ char *response_ptr= index(buffer, ' '); - response_ptr++; - long int version= strtol(response_ptr, (char **)NULL, 10); + char *endptr; + long int version= strtol(response_ptr, &endptr, 10); if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; @@ -246,10 +246,8 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta } instance->major_version= uint8_t(version); - response_ptr= index(response_ptr, '.'); - response_ptr++; - - version= strtol(response_ptr, (char **)NULL, 10); + endptr++; + version= strtol(endptr, &endptr, 10); if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; @@ -257,10 +255,8 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta } instance->minor_version= uint8_t(version); - response_ptr= index(response_ptr, '.'); - response_ptr++; - - version= strtol(response_ptr, (char **)NULL, 10); + endptr++; + version= strtol(endptr, &endptr, 10); if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; @@ -598,8 +594,8 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return MEMCACHED_UNKNOWN_READ_FAILURE; } - char *p; - long int version= strtol(version_buffer, &p, 10); + char *endptr; + long int version= strtol(version_buffer, &endptr, 10); if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; @@ -607,16 +603,18 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan } instance->major_version= uint8_t(version); - version= strtol(p +1, &p, 10); + endptr++; + version= strtol(endptr, &endptr, 10); if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; - return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); + return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version")); } instance->minor_version= uint8_t(version); - version= strtol(p + 1, NULL, 10); - if (errno == ERANGE) + endptr++; + version= strtol(endptr, &endptr, 10); + if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX) { instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX; return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version")); diff --git a/libtest/test.h b/libtest/test.h index d349e54a..d3d65287 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -98,6 +98,15 @@ do \ } \ } while (0) +#define test_skip_hint(__expected, __actual, __hint) \ +do \ +{ \ + if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \ + { \ + return TEST_SKIPPED; \ + } \ +} while (0) + #define test_skip_valgrind() \ do \ { \ diff --git a/m4/bottom.m4 b/m4/bottom.m4 index 798ff2c4..9f99d428 100644 --- a/m4/bottom.m4 +++ b/m4/bottom.m4 @@ -24,19 +24,11 @@ AH_BOTTOM([ # define HAVE_ULONG 1 typedef unsigned long int ulong; #endif + +#define RPACKAGE "memcached" +#define RVERSION "1.4.13" -#if defined(RMEMCACHED_PACKAGE) -#undef VERSION -#define VERSION VERSION_NUMBER -#endif - -#if defined(RMEMCACHED_PACKAGE) -#undef PACKAGE -#define PACKAGE RMEMCACHED_PACKAGE -#endif - - ]) ])dnl CONFIG_EXTRA diff --git a/memcached/include.am b/memcached/include.am index c1d6325d..4d84c6c8 100644 --- a/memcached/include.am +++ b/memcached/include.am @@ -12,9 +12,9 @@ noinst_HEADERS+= memcached/stats.h noinst_HEADERS+= memcached/trace.h noinst_HEADERS+= memcached/util.h -memcached_memcached_SOURCES= memcached_memcached_CFLAGS= memcached_memcached_LDADD= +memcached_memcached_SOURCES= memcached_memcached_SOURCES+= memcached_memcached_SOURCES+= memcached/assoc.c @@ -29,10 +29,8 @@ memcached_memcached_SOURCES+= memcached/thread.c memcached_memcached_SOURCES+= memcached/trace.h memcached_memcached_SOURCES+= memcached/util.c -memcached_memcached_CFLAGS+= -DHAVE_CONFIG_H -std=c99 memcached_memcached_CFLAGS+= ${PTHREAD_CFLAGS} -memcached_memcached_CFLAGS+= -DRMEMCACHED_VERSION="\"1.4.13\"" -memcached_memcached_CFLAGS+= -DRMEMCACHED_PACKAGE="\"memcached\"" +memcached_memcached_CFLAGS+= -DHAVE_CONFIG_H -std=c99 memcached_memcached_LDADD+= $(LIBEVENT_LDFLAGS) memcached_memcached_LDADD+= ${PTHREAD_LIBS} diff --git a/memcached/memcached.c b/memcached/memcached.c index 10e89f80..10374421 100644 --- a/memcached/memcached.c +++ b/memcached/memcached.c @@ -1887,7 +1887,7 @@ static void dispatch_bin_command(conn *c) { switch (c->cmd) { case PROTOCOL_BINARY_CMD_VERSION: if (extlen == 0 && keylen == 0 && bodylen == 0) { - write_bin_response(c, VERSION, 0, 0, strlen(VERSION)); + write_bin_response(c, RVERSION, 0, 0, strlen(RVERSION)); } else { protocol_error = 1; } @@ -2568,7 +2568,7 @@ static void server_stats(ADD_STAT add_stats, conn *c) { APPEND_STAT("pid", "%lu", (long)pid); APPEND_STAT("uptime", "%u", now); APPEND_STAT("time", "%ld", now + (long)process_started); - APPEND_STAT("version", "%s", VERSION); + APPEND_STAT("version", "%s", RVERSION); APPEND_STAT("libevent", "%s", event_get_version()); APPEND_STAT("pointer_size", "%d", (int)(8 * sizeof(void *))); @@ -3363,7 +3363,7 @@ static void process_command(conn *c, char *command) { } else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "version") == 0)) { - out_string(c, "VERSION " VERSION); + out_string(c, "VERSION " RVERSION); } else if (ntokens == 2 && (strcmp(tokens[COMMAND_TOKEN].value, "quit") == 0)) { @@ -4242,7 +4242,12 @@ static int server_socket(const char *interface, } #endif - setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)); + error = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags)); + if (error != 0) + { + perror("setsockopt(SO_REUSEADDR)"); + } + if (IS_UDP(transport)) { maximize_sndbuf(sfd); } else { @@ -4499,7 +4504,7 @@ static void clock_handler(const int fd, const short which, void *arg) { } static void usage(void) { - printf(PACKAGE " " VERSION "\n"); + printf(RPACKAGE " " RVERSION "\n"); printf("-p TCP port number to listen on (default: 11211)\n" "-U UDP port number to listen on (default: 11211, 0 is off)\n" "-s UNIX socket path to listen on (disables network support)\n" @@ -4564,7 +4569,7 @@ static void usage(void) { } static void usage_license(void) { - printf(PACKAGE " " VERSION "\n\n"); + printf(RPACKAGE " " RVERSION "\n\n"); printf( "Copyright (c) 2003, Danga Interactive, Inc. \n" "All rights reserved.\n" diff --git a/tests/include.am b/tests/include.am index a53f45be..165b79b8 100644 --- a/tests/include.am +++ b/tests/include.am @@ -48,6 +48,7 @@ tests_failure_SOURCES+= clients/generator.cc tests_failure_SOURCES+= tests/libmemcached-1.0/callback_counter.cc tests_failure_SOURCES+= tests/libmemcached-1.0/fetch_all_results.cc tests_failure_SOURCES+= tests/libmemcached-1.0/generate.cc +tests_failure_SOURCES+= tests/libmemcached-1.0/print.cc tests_failure_CXXFLAGS = $(AM_CXXFLAGS) tests_failure_DEPENDENCIES= $(TESTS_LDADDS) diff --git a/tests/libmemcached-1.0/include.am b/tests/libmemcached-1.0/include.am index d4b3fc14..e71c4eb8 100644 --- a/tests/libmemcached-1.0/include.am +++ b/tests/libmemcached-1.0/include.am @@ -196,13 +196,14 @@ noinst_PROGRAMS+= tests/atomsmasher tests_testudp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) tests_testudp_SOURCES= -tests_testudp_SOURCES+= tests/mem_udp.cc + tests_testudp_SOURCES+= clients/execute.cc tests_testudp_SOURCES+= clients/generator.cc tests_testudp_SOURCES+= tests/libmemcached-1.0/callback_counter.cc tests_testudp_SOURCES+= tests/libmemcached-1.0/fetch_all_results.cc tests_testudp_SOURCES+= tests/libmemcached-1.0/generate.cc - +tests_testudp_SOURCES+= tests/libmemcached-1.0/print.cc +tests_testudp_SOURCES+= tests/mem_udp.cc tests_testudp_DEPENDENCIES= $(TESTS_LDADDS) tests_testudp_LDADD= $(tests_testudp_DEPENDENCIES) check_PROGRAMS+= tests/testudp @@ -219,6 +220,7 @@ tests_testplus_SOURCES+= clients/generator.cc tests_testplus_SOURCES+= tests/libmemcached-1.0/callback_counter.cc tests_testplus_SOURCES+= tests/libmemcached-1.0/fetch_all_results.cc tests_testplus_SOURCES+= tests/libmemcached-1.0/generate.cc +tests_testplus_SOURCES+= tests/libmemcached-1.0/print.cc tests_testplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX) tests_testplus_DEPENDENCIES= $(TESTS_LDADDS) diff --git a/tests/libmemcached-1.0/print.cc b/tests/libmemcached-1.0/print.cc index 78926581..13c4e1d0 100644 --- a/tests/libmemcached-1.0/print.cc +++ b/tests/libmemcached-1.0/print.cc @@ -47,12 +47,10 @@ using namespace libtest; #include "tests/print.h" -memcached_return_t server_print_callback(const memcached_st *ptr, +memcached_return_t server_print_callback(const memcached_st*, const memcached_server_st *server, void *context) { - (void)ptr; - if (context) { std::cerr << memcached_server_name(server) << ":" << memcached_server_port(server) << std::endl; @@ -60,3 +58,26 @@ memcached_return_t server_print_callback(const memcached_st *ptr, return MEMCACHED_SUCCESS; } + +const char * print_version(memcached_st *memc) +{ + memcached_server_fn callbacks[1]; + callbacks[0]= server_print_version_callback; + memcached_server_cursor(memc, callbacks, NULL, 1); + + return "print_version()"; +} + + +memcached_return_t server_print_version_callback(const memcached_st *, + const memcached_server_st *server, + void *) +{ + std::cerr << "Server: " << memcached_server_name(server) << ":" << memcached_server_port(server) << " " + << int(server->major_version) << "." + << int(server->minor_version) << "." + << int(server->micro_version) + << std::endl; + + return MEMCACHED_SUCCESS; +} diff --git a/tests/libmemcached-1.0/setup_and_teardowns.cc b/tests/libmemcached-1.0/setup_and_teardowns.cc index 95ba4c8d..15c7a3e0 100644 --- a/tests/libmemcached-1.0/setup_and_teardowns.cc +++ b/tests/libmemcached-1.0/setup_and_teardowns.cc @@ -40,6 +40,7 @@ #include +#include "tests/print.h" #include "tests/libmemcached-1.0/setup_and_teardowns.h" #include @@ -61,6 +62,7 @@ memcached_return_t return_value_based_on_buffering(memcached_st *memc) */ test_return_t pre_binary(memcached_st *memc) { + test_true(memcached_server_count(memc) > 0); test_skip(true, libmemcached_util_version_check(memc, 1, 4, 4)); test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, true)); diff --git a/tests/print.h b/tests/print.h index 668daeed..efecc9ed 100644 --- a/tests/print.h +++ b/tests/print.h @@ -40,3 +40,9 @@ memcached_return_t server_print_callback(const memcached_st *ptr, const memcached_server_st *server, void *context); + +memcached_return_t server_print_version_callback(const memcached_st *ptr, + const memcached_server_st *server, + void *context); + +const char * print_version(memcached_st *memc); diff --git a/tests/runner.h b/tests/runner.h index a4b1512d..577f09ba 100644 --- a/tests/runner.h +++ b/tests/runner.h @@ -40,6 +40,7 @@ #include "tests/libmemcached-1.0/generate.h" #include "tests/memc.h" +#include "tests/print.h" class LibmemcachedRunner : public libtest::Runner { public: -- 2.30.2