Improve tesing of command line apps
[awesomized/libmemcached] / libmemcached / dump.cc
index ef4a0ce388fa48b0e1e42883e0c5c3c279e4cbf2..dcbe15b81c5104448b811880582215bf73fdb412 100644 (file)
@@ -6,25 +6,21 @@
   all slabs on servers and "grab" the keys.
 */
 
-#include "common.h"
+#include <libmemcached/common.h>
+
 static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
 {
   memcached_return_t rc= MEMCACHED_SUCCESS;
-  char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-  uint32_t server_key;
-  uint32_t x;
-
-  unlikely (memcached_server_count(ptr) == 0)
-    return MEMCACHED_NO_SERVERS;
 
-  for (server_key= 0; server_key < memcached_server_count(ptr); server_key++)
+  for (uint32_t server_key= 0; server_key < memcached_server_count(ptr); server_key++)
   {
     memcached_server_write_instance_st instance;
     instance= memcached_server_instance_fetch(ptr, server_key);
 
     /* 256 I BELIEVE is the upper limit of slabs */
-    for (x= 0; x < 256; x++)
+    for (uint32_t x= 0; x < 256; x++)
     {
+      char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
       int send_length;
       send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
                             "stats cachedump %u 0 0\r\n", x);
@@ -37,8 +33,10 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb
 
       rc= memcached_do(instance, buffer, (size_t)send_length, true);
 
-      unlikely (rc != MEMCACHED_SUCCESS)
+      if (rc != MEMCACHED_SUCCESS)
+      {
         goto error;
+      }
 
       while (1)
       {
@@ -48,23 +46,29 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb
         if (rc == MEMCACHED_ITEM)
         {
           char *string_ptr, *end_ptr;
-          char *key;
 
           string_ptr= buffer;
           string_ptr+= 5; /* Move past ITEM */
+
           for (end_ptr= string_ptr; isgraph(*end_ptr); end_ptr++) {} ;
-          key= string_ptr;
+
+          char *key= string_ptr;
           key[(size_t)(end_ptr-string_ptr)]= 0;
+
           for (callback_counter= 0; callback_counter < number_of_callbacks; callback_counter++)
           {
             rc= (*callback[callback_counter])(ptr, key, (size_t)(end_ptr-string_ptr), context);
             if (rc != MEMCACHED_SUCCESS)
+            {
               break;
+            }
           }
         }
         else if (rc == MEMCACHED_END)
+        {
           break;
-        else if (rc == MEMCACHED_SERVER_ERROR || rc == MEMCACHED_CLIENT_ERROR)
+        }
+        else if (rc == MEMCACHED_SERVER_ERROR or rc == MEMCACHED_CLIENT_ERROR)
         {
           /* If we try to request stats cachedump for a slab class that is too big
            * the server will return an incorrect error message:
@@ -77,16 +81,22 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb
           break;
         }
         else
+        {
           goto error;
+        }
       }
     }
   }
 
 error:
   if (rc == MEMCACHED_END)
+  {
     return MEMCACHED_SUCCESS;
+  }
   else
+  {
     return rc;
+  }
 }
 
 memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
@@ -102,7 +112,9 @@ memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback
     @todo Fix this so that we just flush, switch to ascii, and then go back to binary.
   */
   if (ptr->flags.binary_protocol)
+  {
     return MEMCACHED_FAILURE;
+  }
 
   return ascii_dump(ptr, callback, context, number_of_callbacks);
 }