X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_purge.c;h=624f624571643779a8af78ab1da810764fa35054;hb=bbd526419742d4a9bb99fcb1a56a80969ebe90fb;hp=c73e97ff9b2b9087936513b16f38a91ccd65854a;hpb=b7f043ada7b39b3e9e244a7f6864a31cd08ad650;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached_purge.c b/libmemcached/memcached_purge.c index c73e97ff..624f6245 100644 --- a/libmemcached/memcached_purge.c +++ b/libmemcached/memcached_purge.c @@ -1,21 +1,17 @@ -#include - #include "common.h" #include "memcached_io.h" +#include "memcached_constants.h" -memcached_return memcached_purge(memcached_server_st *ptr) +memcached_return memcached_purge(memcached_server_st *ptr) { - memcached_return rc; - int32_t timeout; - char buffer[2048]; - memcached_result_st result; - memcached_result_st *result_ptr; + uint32_t x; + memcached_return ret= MEMCACHED_SUCCESS; if (ptr->root->purging || /* already purging */ - (memcached_server_response_count(ptr) < ptr->root->io_msg_watermark && - ptr->io_bytes_sent < ptr->root->io_bytes_watermark) || - (ptr->io_bytes_sent > ptr->root->io_bytes_watermark && - memcached_server_response_count(ptr) < 10)) + (memcached_server_response_count(ptr) < ptr->root->io_msg_watermark && + ptr->io_bytes_sent < ptr->root->io_bytes_watermark) || + (ptr->io_bytes_sent > ptr->root->io_bytes_watermark && + memcached_server_response_count(ptr) < 2)) { return MEMCACHED_SUCCESS; } @@ -28,33 +24,53 @@ memcached_return memcached_purge(memcached_server_st *ptr) /* Force a flush of the buffer to ensure that we don't have the n-1 pending requests buffered up.. */ if (memcached_io_write(ptr, NULL, 0, 1) == -1) - return MEMCACHED_FAILURE; + { + ptr->root->purging= 0; + return MEMCACHED_WRITE_FAILURE; + } WATCHPOINT_ASSERT(ptr->fd != -1); - /* we have already incremented the response counter, and memcached_response - will read out all messages.. To avoid memcached_response to wait forever - for a response to a command I have in my buffer, let's decrement the - response counter :) */ - memcached_server_response_decrement(ptr); - - /* memcached_response may call memcached_io_read, but let's use a short - timeout if there is no data yet */ - timeout= ptr->root->poll_timeout; - ptr->root->poll_timeout= 1; - result_ptr= memcached_result_create(ptr->root, &result); - - if (result_ptr == NULL) - return MEMCACHED_FAILURE; + uint32_t no_msg= memcached_server_response_count(ptr) - 1; + if (no_msg > 0) + { + memcached_result_st result; + memcached_result_st *result_ptr; + char buffer[SMALL_STRING_LEN]; - WATCHPOINT_ASSERT(ptr->fd != -1); - rc= memcached_response(ptr, buffer, sizeof(buffer), &result); - WATCHPOINT_ERROR(rc); - WATCHPOINT_ASSERT(ptr->fd != -1); - ptr->root->poll_timeout= timeout; - memcached_server_response_increment(ptr); - ptr->root->purging = 0; + /* + * 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 + */ + long timeo= ptr->root->poll_timeout; + ptr->root->poll_timeout= 2000; + + result_ptr= memcached_result_create(ptr->root, &result); + WATCHPOINT_ASSERT(result_ptr); - memcached_result_free(&result); + for (x= 0; x < no_msg; x++) + { + memcached_result_reset(result_ptr); + memcached_return rc= memcached_read_one_response(ptr, buffer, + sizeof (buffer), + result_ptr); + /* + * Purge doesn't care for what kind of command results that is received. + * The only kind of errors I care about if is I'm out of sync with the + * protocol or have problems reading data from the network.. + */ + if (rc== MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_UNKNOWN_READ_FAILURE) + { + WATCHPOINT_ERROR(rc); + ret = rc; + memcached_io_reset(ptr); + } + } + + memcached_result_free(result_ptr); + ptr->root->poll_timeout=timeo; + } + ptr->root->purging= 0; - return rc; + return ret; }