Have incr/decr use the number the parser for asci finds.
authorBrian Aker <brian@tangent.org>
Tue, 27 Dec 2011 04:32:16 +0000 (20:32 -0800)
committerBrian Aker <brian@tangent.org>
Tue, 27 Dec 2011 04:32:16 +0000 (20:32 -0800)
libmemcached/auto.cc
libmemcached/common.h
libmemcached/response.cc
libmemcached/response.h

index a04ede523c106e6a479e44a512a16da580db752d..517e5b96fb8faf96f23ee1c50a7ad2544206baad 100644 (file)
@@ -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();
index 5aaf797b795a9c916e106a54f42749fba7602c38..570735045823237e60442750dec3eebc129bc0b0 100644 (file)
@@ -122,7 +122,9 @@ memcached_return_t memcached_server_execute(memcached_st *ptr,
 #include <libmemcached/memcached/protocol_binary.h>
 #include <libmemcached/byteorder.h>
 #include <libmemcached/initialize_query.h>
+#ifdef __cplusplus
 #include <libmemcached/response.h>
+#endif
 #include <libmemcached/namespace.h>
 #include <libmemcached/virtual_bucket.h>
 
index d88ccfbfbed5c6ac880487db08945ce7f072b5a2..35a9f74de40f1c32015fd41cb5f87893b9b58b54 100644 (file)
@@ -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);
 }
index 51f09998deba41e3f905e8b791fefa6a9cf28772..527bf0622c81cd4f686523e852864d9530c713be 100644 (file)
 
 #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);