From b3d84c787cbfa72cc7feca84f60fe476f18c737b Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 28 Dec 2012 17:56:21 -0500 Subject: [PATCH] Update so that we can move to event based fetch. --- libmemcached/common.h | 9 ++++++++- libmemcached/version.cc | 30 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libmemcached/common.h b/libmemcached/common.h index cc38b56d..cc71ac5f 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -215,7 +215,14 @@ extern "C" { memcached_return_t run_distribution(memcached_st *ptr); -#define memcached_server_response_increment(A) (A)->cursor_active_++ +#ifdef __cplusplus +static inline void memcached_server_response_increment(org::libmemcached::Instance* instance) +{ + instance->events(POLLIN); + instance->cursor_active_++; +} +#endif + #define memcached_server_response_decrement(A) (A)->cursor_active_-- #define memcached_server_response_reset(A) (A)->cursor_active_=0 diff --git a/libmemcached/version.cc b/libmemcached/version.cc index 03098161..514f8108 100644 --- a/libmemcached/version.cc +++ b/libmemcached/version.cc @@ -41,7 +41,7 @@ const char * memcached_lib_version(void) return LIBMEMCACHED_VERSION_STRING; } -static inline memcached_return_t memcached_version_textual(memcached_st *ptr) +static inline memcached_return_t memcached_version_textual(memcached_st *memc) { libmemcached_io_vector_st vector[]= { @@ -50,9 +50,9 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) uint32_t success= 0; bool errors_happened= false; - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) + for (uint32_t x= 0; x < memcached_server_count(memc); x++) { - org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); // Optimization, we only fetch version once. if (instance->major_version != UINT8_MAX) @@ -75,7 +75,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) // Collect the returned items org::libmemcached::Instance* instance; memcached_return_t readable_error; - while ((instance= memcached_io_get_readable_server(ptr, readable_error))) + while ((instance= memcached_io_get_readable_server(memc, readable_error))) { memcached_return_t rrc= memcached_response(instance, NULL); if (memcached_failed(rrc)) @@ -89,7 +89,7 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) return errors_happened ? MEMCACHED_SOME_ERRORS : MEMCACHED_SUCCESS; } -static inline memcached_return_t memcached_version_binary(memcached_st *ptr) +static inline memcached_return_t memcached_version_binary(memcached_st *memc) { protocol_binary_request_version request= {}; @@ -103,9 +103,9 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) uint32_t success= 0; bool errors_happened= false; - for (uint32_t x= 0; x < memcached_server_count(ptr); x++) + for (uint32_t x= 0; x < memcached_server_count(memc); x++) { - org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x); + org::libmemcached::Instance* instance= memcached_instance_fetch(memc, x); initialize_binary_request(instance, request.message.header); @@ -130,7 +130,7 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) // Collect the returned items org::libmemcached::Instance* instance; memcached_return_t readable_error; - while ((instance= memcached_io_get_readable_server(ptr, readable_error))) + while ((instance= memcached_io_get_readable_server(memc, readable_error))) { char buffer[32]; memcached_return_t rrc= memcached_response(instance, buffer, sizeof(buffer), NULL); @@ -202,27 +202,27 @@ void memcached_version_instance(org::libmemcached::Instance* instance) } } -memcached_return_t memcached_version(memcached_st *ptr) +memcached_return_t memcached_version(memcached_st *memc) { - if (ptr) + if (memc) { memcached_return_t rc; - if (memcached_failed(rc= initialize_query(ptr, true))) + if (memcached_failed(rc= initialize_query(memc, true))) { return rc; } - if (memcached_is_udp(ptr)) + if (memcached_is_udp(memc)) { return MEMCACHED_NOT_SUPPORTED; } - if (memcached_is_binary(ptr)) + if (memcached_is_binary(memc)) { - return memcached_version_binary(ptr); + return memcached_version_binary(memc); } - return memcached_version_textual(ptr); + return memcached_version_textual(memc); } return MEMCACHED_INVALID_ARGUMENTS; -- 2.30.2