From: Brian Aker Date: Mon, 21 May 2012 06:01:35 +0000 (-0400) Subject: Remove a simple issue that trips up peope providing patches (just allow the class... X-Git-Tag: 1.0.8~2^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fc72bfb155d6938e6d4b7b0e24a6256d88c2a7c3;p=awesomized%2Flibmemcached Remove a simple issue that trips up peope providing patches (just allow the class to cleanup the purge values). --- diff --git a/libmemcached/is.h b/libmemcached/is.h index 25ebe03e..4c4d6f31 100644 --- a/libmemcached/is.h +++ b/libmemcached/is.h @@ -54,7 +54,6 @@ #define memcached_has_replicas(__object) ((__object)->root->number_of_replicas) -#define memcached_set_purging(__object, __value) ((__object)->state.is_purging= (__value)) #define memcached_set_processing_input(__object, __value) ((__object)->state.is_processing_input= (__value)) #define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) #define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated= (__value)) diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 2bcf6fa8..548f2355 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -184,11 +184,6 @@ memcached_st *memcached_create(memcached_st *ptr) ptr->options.is_allocated= true; } -#if 0 - memcached_set_purging(ptr, false); - memcached_set_processing_input(ptr, false); -#endif - if (_memcached_init(ptr) == false) { memcached_free(ptr); diff --git a/libmemcached/purge.cc b/libmemcached/purge.cc index 38e4552a..841af82e 100644 --- a/libmemcached/purge.cc +++ b/libmemcached/purge.cc @@ -39,6 +39,45 @@ #include +#define memcached_set_purging(__object, __value) ((__object)->state.is_purging= (__value)) + +class Purge +{ +public: + Purge(memcached_st* arg) : + _memc(arg) + { + memcached_set_purging(_memc, true); + } + + ~Purge() + { + memcached_set_purging(_memc, false); + } + +private: + memcached_st* _memc; +}; + +class PollTimeout +{ +public: + PollTimeout(memcached_st* arg) : + _timeout(arg->poll_timeout), + _origin(arg->poll_timeout) + { + _origin = 2000; + } + + ~PollTimeout() + { + _origin= _timeout; + } + +private: + int32_t _timeout; + int32_t& _origin; +}; bool memcached_purge(memcached_server_write_instance_st ptr) { @@ -57,7 +96,7 @@ bool memcached_purge(memcached_server_write_instance_st ptr) memcached_io_write and memcached_response may call memcached_purge so we need to be able stop any recursion.. */ - memcached_set_purging(root, true); + Purge set_purge(root); WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); /* @@ -66,8 +105,6 @@ bool memcached_purge(memcached_server_write_instance_st ptr) */ if (memcached_io_write(ptr) == false) { - memcached_set_purging(root, true); - memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); return false; } @@ -78,18 +115,16 @@ bool memcached_purge(memcached_server_write_instance_st ptr) if (no_msg > 0) { memcached_result_st result; - memcached_result_st *result_ptr; /* * We need to increase the timeout, because we might be waiting for * data to be sent from the server (the commands was in the output buffer * and just flushed */ - const int32_t timeo= ptr->root->poll_timeout; - root->poll_timeout= 2000; + PollTimeout poll_timeout(ptr->root); - result_ptr= memcached_result_create(root, &result); - WATCHPOINT_ASSERT(result_ptr); + memcached_result_st* result_ptr= memcached_result_create(root, &result); + assert(result_ptr); for (uint32_t x= 0; x < no_msg; x++) { @@ -124,9 +159,7 @@ bool memcached_purge(memcached_server_write_instance_st ptr) } memcached_result_free(result_ptr); - root->poll_timeout= timeo; } - memcached_set_purging(root, false); return is_successful; }