Merge trunk
[m6w6/libmemcached] / libmemcached / do.cc
index 14824a641aec79c659c8fbdc8f94ae912894f176..551b28ea57ce21393fcbaefbb47dc800b7f20724 100644 (file)
@@ -9,19 +9,18 @@
  *
  */
 
-#include "common.h"
+#include <libmemcached/common.h>
 
 memcached_return_t memcached_do(memcached_server_write_instance_st ptr, const void *command,
                                 size_t command_length, bool with_flush)
 {
-  memcached_return_t rc;
-  ssize_t sent_length;
-
-  WATCHPOINT_ASSERT(command_length);
-  WATCHPOINT_ASSERT(command);
+  assert_msg(command_length, "Programming error, somehow a command had a length of zero");
+  assert_msg(command, "Programming error, somehow a command was NULL");
 
-  if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
+  memcached_return_t rc;
+  if (memcached_failed(rc= memcached_connect(ptr)))
   {
+    WATCHPOINT_ASSERT(rc == memcached_last_error(ptr->root));
     WATCHPOINT_ERROR(rc);
     return rc;
   }
@@ -36,9 +35,9 @@ memcached_return_t memcached_do(memcached_server_write_instance_st ptr, const vo
     memcached_io_write(ptr, NULL, 0, true);
   }
 
-  sent_length= memcached_io_write(ptr, command, command_length, with_flush);
+  ssize_t sent_length= memcached_io_write(ptr, command, command_length, with_flush);
 
-  if (sent_length == -1 || (size_t)sent_length != command_length)
+  if (sent_length == -1 or size_t(sent_length) != command_length)
   {
     rc= MEMCACHED_WRITE_FAILURE;
   }
@@ -55,14 +54,14 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
                                  bool with_flush)
 {
   memcached_return_t rc;
-  ssize_t sent_length;
 
   WATCHPOINT_ASSERT(count);
   WATCHPOINT_ASSERT(vector);
 
-  if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
+  if (memcached_failed(rc= memcached_connect(ptr)))
   {
     WATCHPOINT_ERROR(rc);
+    assert_msg(ptr->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
     return rc;
   }
 
@@ -76,7 +75,7 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
     memcached_io_write(ptr, NULL, 0, true);
   }
 
-  sent_length= memcached_io_writev(ptr, vector, count, with_flush);
+  ssize_t sent_length= memcached_io_writev(ptr, vector, count, with_flush);
 
   size_t command_length= 0;
   for (uint32_t x= 0; x < count; ++x, vector++)
@@ -84,7 +83,7 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr,
     command_length+= vector->length;
   }
 
-  if (sent_length == -1 || (size_t)sent_length != command_length)
+  if (sent_length == -1 or size_t(sent_length) != command_length)
   {
     rc= MEMCACHED_WRITE_FAILURE;
     WATCHPOINT_ERROR(rc);