Merge in more updates for docs (we are just going to check them all in so that users...
[awesomized/libmemcached] / libmemcached / dump.c
index 4c1006e784cd6d46dfb636ac126dd1836d65758b..18c159748bdd1e70d24e5fd78f6fd4ac285cdc3f 100644 (file)
@@ -9,24 +9,32 @@
 #include "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= 0;
+  memcached_return_t rc= MEMCACHED_SUCCESS;
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-  size_t send_length;
   uint32_t server_key;
   uint32_t x;
 
-  unlikely (ptr->number_of_hosts == 0)
+  unlikely (memcached_server_count(ptr) == 0)
     return MEMCACHED_NO_SERVERS;
 
-  for (server_key= 0; server_key < ptr->number_of_hosts; server_key++)
+  for (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++)
     {
-      send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 
-                                     "stats cachedump %u 0 0\r\n", x);
+      int send_length;
+      send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+                            "stats cachedump %u 0 0\r\n", x);
 
-      rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, 1);
+      if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
+      {
+        return MEMCACHED_FAILURE;
+      }
+
+      rc= memcached_do(instance, buffer, (size_t)send_length, true);
 
       unlikely (rc != MEMCACHED_SUCCESS)
         goto error;
@@ -34,7 +42,7 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb
       while (1)
       {
         uint32_t callback_counter;
-        rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+        rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
 
         if (rc == MEMCACHED_ITEM)
         {
@@ -82,10 +90,18 @@ error:
 
 memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *callback, void *context, uint32_t number_of_callbacks)
 {
-  /* No support for Binary protocol yet */
+  memcached_return_t rc;
+  if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS)
+  {
+    return rc;
+  }
+
+  /* 
+    No support for Binary protocol yet
+    @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);
 }
-