Work on C++ library. Pulled out result methods - need to define 'result'
[awesomized/libmemcached] / lib / memcached_verbosity.c
index 55a51842a8211a12449a3c5132a1ad345642b49f..f599787bd070697c011bf566224b210348b33e34 100644 (file)
@@ -1,44 +1,31 @@
-#include <memcached.h>
+#include "common.h"
 
 memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity)
 {
   unsigned int x;
-  size_t send_length, sent_length;
+  size_t send_length;
   memcached_return rc;
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
 
-  rc= memcached_connect(ptr);
-
-  if (rc != MEMCACHED_SUCCESS)
-    rc= MEMCACHED_SOME_ERRORS;
-
   send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 
                         "verbosity %u\r\n", verbosity);
   if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
     return MEMCACHED_WRITE_FAILURE;
 
+  rc= MEMCACHED_SUCCESS;
   for (x= 0; x < ptr->number_of_hosts; x++)
   {
-    memcached_return rc;
-
-    sent_length= write(ptr->hosts[x].fd, buffer, send_length);
-
-    if (sent_length == -1)
-    {
-      fprintf(stderr, "error %s: write: %m\n", __FUNCTION__);
-      return MEMCACHED_WRITE_FAILURE;
-    }
+    memcached_return rrc;
 
-    if (sent_length != send_length)
+    rrc= memcached_do(&ptr->hosts[x], buffer, send_length, 1);
+    if (rrc != MEMCACHED_SUCCESS)
     {
-      fprintf(stderr, "error %s: short write %d %d: %m\n",
-             __FUNCTION__, sent_length, send_length);
-      return MEMCACHED_WRITE_FAILURE;
+      rc= MEMCACHED_SOME_ERRORS;
+      continue;
     }
 
-    rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
-
-    if (rc != MEMCACHED_SUCCESS)
+    rrc= memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+    if (rrc != MEMCACHED_SUCCESS)
       rc= MEMCACHED_SOME_ERRORS;
   }