From bd5ae730cbd95ac48993f8d2504dfe298c3637c7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 6 Feb 2014 15:24:51 +0100 Subject: [PATCH] Updates for compilation with older libmemcached Use memcached_create + memcached_server_add instead of memcached. Use memcached_strerror instead of memcached_last_error. Check for memcached_return_t during configure and use memcached_return instead of memcached_return_t for older libmemcached versions. --- configure.ac | 9 +++++++++ src/zoom-memcached.c | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 60aca07..3b951a9 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,15 @@ if test "$memcached" != "no" -a -n "$libgcryptversion"; then AC_CHECK_LIB([memcached],[memcached_get]) if test "$ac_cv_lib_memcached_memcached_get" = "yes"; then AC_CHECK_HEADERS([libmemcached/memcached.h]) + if test "$ac_cv_header_libmemcached_memcached_h" = "yes"; then + AC_TRY_COMPILE( + [ +#include + ],[ + memcached_return_t x; + ],[AC_DEFINE([HAVE_MEMCACHED_RETURN_T],[1],[Define to 1 if memcached_return_t is defined])] + ) + fi fi fi dnl ------ GNU TLS diff --git a/src/zoom-memcached.c b/src/zoom-memcached.c index d92758e..6686bd5 100644 --- a/src/zoom-memcached.c +++ b/src/zoom-memcached.c @@ -20,6 +20,11 @@ #include #include +#if HAVE_MEMCACHED_RETURN_T +#else +typedef memcached_return memcached_return_t; +#endif + void ZOOM_memcached_init(ZOOM_connection c) { #if HAVE_LIBMEMCACHED_MEMCACHED_H @@ -49,10 +54,17 @@ int ZOOM_memcached_configure(ZOOM_connection c) if (val && *val) { #if HAVE_LIBMEMCACHED_MEMCACHED_H - c->mc_st = memcached(val, strlen(val)); - if (!c->mc_st) + memcached_return_t rc; + + c->mc_st = memcached_create(0); + rc = memcached_server_add(c->mc_st, val, 11211); + yaz_log(YLOG_LOG, "memcached_server_add host=%s rc=%u %s", + val, (unsigned) rc, memcached_strerror(c->mc_st, rc)); + if (rc != MEMCACHED_SUCCESS) { ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, val); + memcached_free(c->mc_st); + c->mc_st = 0; return -1; } memcached_behavior_set(c->mc_st, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); @@ -172,7 +184,7 @@ void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset, key, strlen(str) + 1 + oi_len, expiration, flags); yaz_log(YLOG_LOG, "Store hit count key=%s value=%s oi_len=%d rc=%u %s", wrbuf_cstr(resultset->mc_key), str, oi_len, (unsigned) rc, - memcached_last_error_message(c->mc_st)); + memcached_strerror(c->mc_st, rc)); odr_destroy(odr); } #endif @@ -215,7 +227,7 @@ void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr, yaz_log(YLOG_LOG, "Store record key=%s val=%s rc=%u %s", wrbuf_cstr(k), wrbuf_cstr(rec_sha1), (unsigned) rc, - memcached_last_error_message(r->connection->mc_st)); + memcached_strerror(r->connection->mc_st, rc)); rc = memcached_add(r->connection->mc_st, wrbuf_buf(rec_sha1), wrbuf_len(rec_sha1), @@ -224,7 +236,7 @@ void ZOOM_memcached_add(ZOOM_resultset r, Z_NamePlusRecord *npr, yaz_log(YLOG_LOG, "Add record key=%s rec_len=%d rc=%u %s", wrbuf_cstr(rec_sha1), rec_len, (unsigned) rc, - memcached_last_error_message(r->connection->mc_st)); + memcached_strerror(r->connection->mc_st, rc)); odr_destroy(odr); wrbuf_destroy(k); -- 1.7.10.4