From 7f192e3ce089fb207186dd4079cc377c90631976 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 10 Jun 2010 18:43:08 -0700 Subject: [PATCH] Added libmemcached_ping() to memcached utility library. --- ChangeLog | 1 + libmemcached/include.am | 5 ++++- libmemcached/memcached_util.h | 3 ++- libmemcached/util/pool.c | 11 +++++++++++ tests/mem_functions.c | 21 +++++++++++++++++++++ tests/test.h | 8 +++++--- 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74281df8..85cc9728 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 0.41 * Added --file for memcat. + * Added limemcached_ping() to libmemcached_util 0.40 Thu Apr 22 19:01:25 PDT 2010 * Placed retry logic in for busted resolvers diff --git a/libmemcached/include.am b/libmemcached/include.am index dc125bd7..30095b14 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -121,11 +121,14 @@ libmemcached_libmemcached_la_LDFLAGS= ${AM_LDFLAGS} -version-info ${MEMCACHED_LI if BUILD_LIBMEMCACHEDUTIL nobase_include_HEADERS+= \ libmemcached/memcached_util.h \ + libmemcached/util/ping.h \ libmemcached/util/pool.h lib_LTLIBRARIES+= libmemcached/libmemcachedutil.la endif -libmemcached_libmemcachedutil_la_SOURCES= libmemcached/util/pool.c +libmemcached_libmemcachedutil_la_SOURCES= \ + libmemcached/util/ping.c \ + libmemcached/util/pool.c libmemcached_libmemcachedutil_la_LIBADD= libmemcached/libmemcached.la libmemcached_libmemcachedutil_la_LDFLAGS= ${AM_LDFLAGS} -version-info 0:0:0 libmemcached_libmemcachedutil_la_DEPENDENCIES= libmemcached/libmemcached.la diff --git a/libmemcached/memcached_util.h b/libmemcached/memcached_util.h index a20b665b..925745e7 100644 --- a/libmemcached/memcached_util.h +++ b/libmemcached/memcached_util.h @@ -7,7 +7,7 @@ * * Summary: Connection pool library. * - * Author: Trond Norbye + * Author: Trond Norbye, Brian Aker * */ @@ -15,6 +15,7 @@ #ifndef __LIBMEMCACHED__MEMCACHED_UTIL_H__ #define __LIBMEMCACHED__MEMCACHED_UTIL_H__ +#include #include #endif /* __LIBMEMCACHED__MEMCACHED_UTIL_H__ */ diff --git a/libmemcached/util/pool.c b/libmemcached/util/pool.c index 012d550f..bd4fdf98 100644 --- a/libmemcached/util/pool.c +++ b/libmemcached/util/pool.c @@ -1,3 +1,14 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: connects to a host, and makes sure it is alive. + * + */ + /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ #include "libmemcached/common.h" #include "libmemcached/memcached_util.h" diff --git a/tests/mem_functions.c b/tests/mem_functions.c index ba99c0be..9bd9334e 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -3145,6 +3145,8 @@ static test_return_t output_ketama_weighted_keys(memcached_st *trash) char *hostname = memc->hosts[server_idx].hostname; in_port_t port = memc->hosts[server_idx].port; fprintf(fp, "key %s is on host /%s:%u\n", key, hostname, port); + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, host_index); } fclose(fp); #endif @@ -4423,6 +4425,24 @@ static test_return_t connection_pool_test(memcached_st *memc) test_true(memcached_pool_destroy(pool) == memc); return TEST_SUCCESS; } + +static test_return_t ping_test(memcached_st *memc) +{ + memcached_return_t rc; + memcached_server_instance_st instance= + memcached_server_instance_by_position(memc, 0); + + // Test both the version that returns a code, and the one that does not. + test_true(libmemcached_ping(memcached_server_name(instance), + memcached_server_port(instance), NULL)); + + test_true(libmemcached_ping(memcached_server_name(instance), + memcached_server_port(instance), &rc)); + + test_true(rc == MEMCACHED_SUCCESS); + + return TEST_SUCCESS; +} #endif static test_return_t replication_set_test(memcached_st *memc) @@ -6088,6 +6108,7 @@ test_st tests[] ={ {"analyzer", 1, (test_callback_fn)analyzer_test}, #ifdef HAVE_LIBMEMCACHEDUTIL {"connectionpool", 1, (test_callback_fn)connection_pool_test }, + {"ping", 1, (test_callback_fn)ping_test }, #endif {"test_get_last_disconnect", 1, (test_callback_fn)test_get_last_disconnect}, {"verbosity", 1, (test_callback_fn)test_verbosity}, diff --git a/tests/test.h b/tests/test.h index cd58a80d..77aa5303 100644 --- a/tests/test.h +++ b/tests/test.h @@ -152,9 +152,11 @@ const char *test_strerror(test_return_t code); #define test_fail(A) \ do \ { \ - fprintf(stderr, "\nFailed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ - create_core(); \ - return TEST_FAILURE; \ + if (1) { \ + fprintf(stderr, "\nFailed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + create_core(); \ + return TEST_FAILURE; \ + } \ } while (0) #define test_true(A) \ -- 2.30.2