From: Brian Aker Date: Tue, 27 Dec 2011 04:32:16 +0000 (-0800) Subject: Have incr/decr use the number the parser for asci finds. X-Git-Tag: 1.0.3~3^2~1^2~17 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=06d0eaed5e274bc0ba93a3a61788a4bab480adf2;p=m6w6%2Flibmemcached Have incr/decr use the number the parser for asci finds. --- diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index a04ede52..517e5b96 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -42,7 +42,7 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, uint64_t offset, - uint64_t *value) + uint64_t& numeric_value) { char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; uint32_t server_key; @@ -84,43 +84,11 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, memcached_return_t rc= memcached_vdo(instance, vector, 6, true); if (reply == false or memcached_failed(rc)) { + numeric_value= UINT64_MAX; return rc; } - rc= memcached_response(instance, buffer, sizeof(buffer), NULL); - - if (rc != MEMCACHED_SUCCESS) - { - return memcached_set_error(*instance, rc, MEMCACHED_AT); - } - - /* - So why recheck responce? Because the protocol is brain dead :) - The number returned might end up equaling one of the string - values. Less chance of a mistake with strncmp() so we will - use it. We still called memcached_response() though since it - worked its magic for non-blocking IO. - */ - if (not strncmp(buffer, memcached_literal_param("ERROR\r\n"))) - { - *value= 0; - rc= MEMCACHED_PROTOCOL_ERROR; - } - else if (not strncmp(buffer, memcached_literal_param("CLIENT_ERROR\r\n"))) - { - *value= 0; - rc= MEMCACHED_PROTOCOL_ERROR; - } - else if (not strncmp(buffer, memcached_literal_param("NOT_FOUND\r\n"))) - { - *value= 0; - rc= MEMCACHED_NOTFOUND; - } - else - { - *value= strtoull(buffer, (char **)NULL, 10); - rc= MEMCACHED_SUCCESS; - } + rc= memcached_response(instance, buffer, sizeof(buffer), NULL, numeric_value); return memcached_set_error(*instance, rc, MEMCACHED_AT); } @@ -228,7 +196,7 @@ memcached_return_t memcached_increment_by_key(memcached_st *ptr, } else { - rc= text_incr_decr(ptr, true, group_key, group_key_length, key, key_length, offset, value); + rc= text_incr_decr(ptr, true, group_key, group_key_length, key, key_length, offset, *value); } LIBMEMCACHED_MEMCACHED_INCREMENT_END(); @@ -270,7 +238,7 @@ memcached_return_t memcached_decrement_by_key(memcached_st *ptr, } else { - rc= text_incr_decr(ptr, false, group_key, group_key_length, key, key_length, offset, value); + rc= text_incr_decr(ptr, false, group_key, group_key_length, key, key_length, offset, *value); } LIBMEMCACHED_MEMCACHED_DECREMENT_END(); diff --git a/libmemcached/common.h b/libmemcached/common.h index 5aaf797b..57073504 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -122,7 +122,9 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #include #include #include +#ifdef __cplusplus #include +#endif #include #include diff --git a/libmemcached/response.cc b/libmemcached/response.cc index d88ccfbf..35a9f74d 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -187,8 +187,10 @@ read_error: static memcached_return_t textual_read_one_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, - memcached_result_st *result) + memcached_result_st *result, + uint64_t& numeric_value) { + numeric_value= UINT64_MAX; size_t total_read; memcached_return_t rc= memcached_io_readline(ptr, buffer, buffer_length, total_read); @@ -350,6 +352,8 @@ static memcached_return_t textual_read_one_response(memcached_server_write_insta return MEMCACHED_UNKNOWN_READ_FAILURE; } + numeric_value= uint64_t(auto_return_value); + WATCHPOINT_STRING(buffer); return MEMCACHED_SUCCESS; } @@ -645,6 +649,16 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result) +{ + uint64_t numeric_value; + + return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); +} + +memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, + char *buffer, size_t buffer_length, + memcached_result_st *result, + uint64_t& numeric_value) { memcached_server_response_decrement(ptr); @@ -661,7 +675,7 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s } else { - rc= textual_read_one_response(ptr, buffer, buffer_length, result); + rc= textual_read_one_response(ptr, buffer, buffer_length, result, numeric_value); } if (rc == MEMCACHED_UNKNOWN_READ_FAILURE or @@ -679,6 +693,16 @@ memcached_return_t memcached_read_one_response(memcached_server_write_instance_s memcached_return_t memcached_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result) +{ + uint64_t numeric_value; + + return memcached_response(ptr, buffer, buffer_length, result, numeric_value); +} + +memcached_return_t memcached_response(memcached_server_write_instance_st ptr, + char *buffer, size_t buffer_length, + memcached_result_st *result, + uint64_t& numeric_value) { /* We may have old commands in the buffer not set, first purge */ if ((ptr->root->flags.no_block) && (memcached_is_processing_input(ptr->root) == false)) @@ -695,7 +719,7 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, { while (memcached_server_response_count(ptr) > 1) { - memcached_return_t rc= memcached_read_one_response(ptr, buffer, buffer_length, result); + memcached_return_t rc= memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); if (rc != MEMCACHED_END && rc != MEMCACHED_STORED && @@ -711,5 +735,5 @@ memcached_return_t memcached_response(memcached_server_write_instance_st ptr, } } - return memcached_read_one_response(ptr, buffer, buffer_length, result); + return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value); } diff --git a/libmemcached/response.h b/libmemcached/response.h index 51f09998..527bf062 100644 --- a/libmemcached/response.h +++ b/libmemcached/response.h @@ -37,21 +37,21 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - /* Read a single response from the server */ -LIBMEMCACHED_LOCAL memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result); -LIBMEMCACHED_LOCAL +memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr, + char *buffer, size_t buffer_length, + memcached_result_st *result, + uint64_t& numeric_value); + memcached_return_t memcached_response(memcached_server_write_instance_st ptr, char *buffer, size_t buffer_length, memcached_result_st *result); -#ifdef __cplusplus -} -#endif +memcached_return_t memcached_response(memcached_server_write_instance_st ptr, + char *buffer, size_t buffer_length, + memcached_result_st *result, + uint64_t& numeric_value);