Update rules for sphinx`
[awesomized/libmemcached] / libmemcached / get.cc
index 73802e20fb3af23b7e806d450af2e2706c76118e..1f7e775c3cc57a258eb47d554b263782bf604e26 100644 (file)
@@ -2,7 +2,7 @@
  * 
  *  Libmemcached library
  *
- *  Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
+ *  Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
  *  Copyright (C) 2006-2009 Brian Aker All rights reserved.
  *
  *  Redistribution and use in source and binary forms, with or without
@@ -50,15 +50,14 @@ char *memcached_get(memcached_st *ptr, const char *key,
                               flags, error);
 }
 
-static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
-                                                     const char *group_key,
-                                                     size_t group_key_length,
-                                                     const char * const *keys,
-                                                     const size_t *key_length,
-                                                     size_t number_of_keys,
-                                                     bool mget_mode);
-
-char *memcached_get_by_key(memcached_st *ptr,
+static memcached_return_t __mget_by_key_real(memcached_st *ptr,
+                                             const char *group_key,
+                                             size_t group_key_length,
+                                             const char * const *keys,
+                                             const size_t *key_length,
+                                             size_t number_of_keys,
+                                             const bool mget_mode);
+char *memcached_get_by_key(memcached_st *shell,
                            const char *group_key,
                            size_t group_key_length,
                            const char *key, size_t key_length,
@@ -66,6 +65,7 @@ char *memcached_get_by_key(memcached_st *ptr,
                            uint32_t *flags,
                            memcached_return_t *error)
 {
+  Memcached* ptr= memcached2Memcached(shell);
   memcached_return_t unused;
   if (error == NULL)
   {
@@ -79,9 +79,9 @@ char *memcached_get_by_key(memcached_st *ptr,
   }
 
   /* Request the key */
-  *error= memcached_mget_by_key_real(ptr, group_key, group_key_length,
-                                     (const char * const *)&key, &key_length, 
-                                     1, false);
+  *error= __mget_by_key_real(ptr, group_key, group_key_length,
+                             (const char * const *)&key, &key_length, 
+                             1, false);
   if (ptr)
   {
     assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented.");
@@ -186,20 +186,20 @@ memcached_return_t memcached_mget(memcached_st *ptr,
 }
 
 static memcached_return_t binary_mget_by_key(memcached_st *ptr,
-                                             uint32_t master_server_key,
-                                             bool is_group_key_set,
+                                             const uint32_t master_server_key,
+                                             const bool is_group_key_set,
+                                             const char * const *keys,
+                                             const size_t *key_length,
+                                             const size_t number_of_keys,
+                                             const bool mget_mode);
+
+static memcached_return_t __mget_by_key_real(memcached_st *ptr,
+                                             const char *group_key,
+                                             const size_t group_key_length,
                                              const char * const *keys,
                                              const size_t *key_length,
                                              size_t number_of_keys,
-                                             bool mget_mode);
-
-static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
-                                                     const char *group_key,
-                                                     size_t group_key_length,
-                                                     const char * const *keys,
-                                                     const size_t *key_length,
-                                                     size_t number_of_keys,
-                                                     bool mget_mode)
+                                             const bool mget_mode)
 {
   bool failures_occured_in_sending= false;
   const char *get_command= "get";
@@ -244,9 +244,9 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
   */
   for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
   {
-    org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
+    memcached_instance_st* instance= memcached_instance_fetch(ptr, x);
 
-    if (memcached_instance_response_count(instance))
+    if (instance->response_count())
     {
       char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
 
@@ -255,7 +255,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
         memcached_io_write(instance);
       }
 
-      while(memcached_instance_response_count(instance))
+      while(instance->response_count())
       {
         (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
       }
@@ -293,7 +293,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
       server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]);
     }
 
-    org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
+    memcached_instance_st* instance= memcached_instance_fetch(ptr, server_key);
 
     libmemcached_io_vector_st vector[]=
     {
@@ -304,7 +304,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
     };
 
 
-    if (memcached_instance_response_count(instance) == 0)
+    if (instance->response_count() == 0)
     {
       rc= memcached_connect(instance);
 
@@ -315,16 +315,16 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
       }
       hosts_connected++;
 
-      if ((memcached_io_writev(instance, vector, 4, false)) == false)
+      if ((memcached_io_writev(instance, vector, 1, false)) == false)
       {
         failures_occured_in_sending= true;
         continue;
       }
-      WATCHPOINT_ASSERT(instance->cursor_active == 0);
+      WATCHPOINT_ASSERT(instance->cursor_active_ == 0);
       memcached_instance_response_increment(instance);
-      WATCHPOINT_ASSERT(instance->cursor_active == 1);
+      WATCHPOINT_ASSERT(instance->cursor_active_ == 1);
     }
-    else
+
     {
       if ((memcached_io_writev(instance, (vector + 1), 3, false)) == false)
       {
@@ -354,9 +354,9 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
   bool success_happened= false;
   for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
   {
-    org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
+    memcached_instance_st* instance= memcached_instance_fetch(ptr, x);
 
-    if (memcached_instance_response_count(instance))
+    if (instance->response_count())
     {
       /* We need to do something about non-connnected hosts in the future */
       if ((memcached_io_write(instance, "\r\n", 2, true)) == -1)
@@ -385,15 +385,15 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr,
   return MEMCACHED_FAILURE; // Complete failure occurred
 }
 
-memcached_return_t memcached_mget_by_key(memcached_st *ptr,
+memcached_return_t memcached_mget_by_key(memcached_st *shell,
                                          const char *group_key,
                                          size_t group_key_length,
                                          const char * const *keys,
                                          const size_t *key_length,
                                          size_t number_of_keys)
 {
-  return memcached_mget_by_key_real(ptr, group_key, group_key_length, keys,
-                                    key_length, number_of_keys, true);
+  Memcached* ptr= memcached2Memcached(shell);
+  return __mget_by_key_real(ptr, group_key, group_key_length, keys, key_length, number_of_keys, true);
 }
 
 memcached_return_t memcached_mget_execute(memcached_st *ptr,
@@ -409,7 +409,7 @@ memcached_return_t memcached_mget_execute(memcached_st *ptr,
                                        context, number_of_callbacks);
 }
 
-memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr,
+memcached_return_t memcached_mget_execute_by_key(memcached_st *shell,
                                                  const char *group_key,
                                                  size_t group_key_length,
                                                  const char * const *keys,
@@ -419,6 +419,7 @@ memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr,
                                                  void *context,
                                                  unsigned int number_of_callbacks)
 {
+  Memcached* ptr= memcached2Memcached(shell);
   memcached_return_t rc;
   if (memcached_failed(rc= initialize_query(ptr, false)))
   {
@@ -447,15 +448,16 @@ memcached_return_t memcached_mget_execute_by_key(memcached_st *ptr,
   rc= memcached_mget_by_key(ptr, group_key, group_key_length, keys,
                             key_length, number_of_keys);
   ptr->callbacks= original_callbacks;
+
   return rc;
 }
 
 static memcached_return_t simple_binary_mget(memcached_st *ptr,
-                                             uint32_t master_server_key,
+                                             const uint32_t master_server_key,
                                              bool is_group_key_set,
                                              const char * const *keys,
                                              const size_t *key_length,
-                                             size_t number_of_keys, bool mget_mode)
+                                             const size_t number_of_keys, const bool mget_mode)
 {
   memcached_return_t rc= MEMCACHED_NOTFOUND;
 
@@ -478,9 +480,9 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr,
       server_key= memcached_generate_hash_with_redistribution(ptr, keys[x], key_length[x]);
     }
 
-    org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server_key);
+    memcached_instance_st* instance= memcached_instance_fetch(ptr, server_key);
 
-    if (memcached_instance_response_count(instance) == 0)
+    if (instance->response_count() == 0)
     {
       rc= memcached_connect(instance);
       if (memcached_failed(rc))
@@ -500,17 +502,17 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr,
       request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
     }
 
-    memcached_return_t vk;
-    vk= memcached_validate_key_length(key_length[x],
-                                      ptr->flags.binary_protocol);
-    if (vk != MEMCACHED_SUCCESS)
     {
-      if (x > 0)
+      memcached_return_t vk= memcached_validate_key_length(key_length[x], ptr->flags.binary_protocol);
+      if (vk != MEMCACHED_SUCCESS)
       {
-        memcached_io_reset(instance);
-      }
+        if (x > 0)
+        {
+          memcached_io_reset(instance);
+        }
 
-      return vk;
+        return vk;
+      }
     }
 
     request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->_namespace)));
@@ -551,20 +553,13 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr,
 
     for (uint32_t x= 0; x < memcached_server_count(ptr); ++x)
     {
-      org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, x);
-      initialize_binary_request(instance, request.message.header);
+      memcached_instance_st* instance= memcached_instance_fetch(ptr, x);
 
-      if (memcached_instance_response_count(instance))
+      if (instance->response_count())
       {
-        if (memcached_io_write(instance) == false)
-        {
-          memcached_instance_response_reset(instance);
-          memcached_io_reset(instance);
-          rc= MEMCACHED_SOME_ERRORS;
-        }
-
-        if (memcached_io_write(instance, request.bytes,
-                               sizeof(request.bytes), true) == -1)
+        initialize_binary_request(instance, request.message.header);
+        if ((memcached_io_write(instance) == false) or
+            (memcached_io_write(instance, request.bytes, sizeof(request.bytes), true) == -1))
         {
           memcached_instance_response_reset(instance);
           memcached_io_reset(instance);
@@ -574,7 +569,6 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr,
     }
   }
 
-
   return rc;
 }
 
@@ -583,7 +577,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr,
                                                   bool* dead_servers,
                                                   const char *const *keys,
                                                   const size_t *key_length,
-                                                  size_t number_of_keys)
+                                                  const size_t number_of_keys)
 {
   memcached_return_t rc= MEMCACHED_NOTFOUND;
   uint32_t start= 0;
@@ -602,9 +596,11 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr,
     for (uint32_t x= 0; x < number_of_keys; ++x)
     {
       if (hash[x] == memcached_server_count(ptr))
+      {
         continue; /* Already successfully sent */
+      }
 
-      uint32_t server= hash[x] + replica;
+      uint32_t server= hash[x] +replica;
 
       /* In case of randomized reads */
       if (randomize_read and ((server + start) <= (hash[x] + ptr->number_of_replicas)))
@@ -622,9 +618,9 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr,
         continue;
       }
 
-      org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, server);
+      memcached_instance_st* instance= memcached_instance_fetch(ptr, server);
 
-      if (memcached_instance_response_count(instance) == 0)
+      if (instance->response_count() == 0)
       {
         rc= memcached_connect(instance);
 
@@ -683,12 +679,12 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr,
 }
 
 static memcached_return_t binary_mget_by_key(memcached_st *ptr,
-                                             uint32_t master_server_key,
+                                             const uint32_t master_server_key,
                                              bool is_group_key_set,
                                              const char * const *keys,
                                              const size_t *key_length,
-                                             size_t number_of_keys,
-                                             bool mget_mode)
+                                             const size_t number_of_keys,
+                                             const bool mget_mode)
 {
   if (ptr->number_of_replicas == 0)
   {