Update writev
[m6w6/libmemcached] / libmemcached / do.cc
index 3c3519c27b9cccb29df440a9e4719735bb3be424..61a143b888d798ace2a3361a63db912ab183b9a7 100644 (file)
@@ -50,26 +50,39 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance,
     msg.msg_iov= (struct iovec*)vector;
     msg.msg_iovlen= count;
 
-    if (::sendmsg(instance->fd, &msg, 0) < 1)
+    uint32_t retry= 5;
+    while (--retry)
     {
-      return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+      ssize_t sendmsg_length= ::sendmsg(instance->fd, &msg, 0);
+      if (sendmsg_length > 0)
+      {
+        break;
+      }
+      else if (sendmsg_length < 0)
+      {
+        if (errno == EMSGSIZE)
+        {
+          return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+        }
+
+        return memcached_set_errno(*instance, errno, MEMCACHED_AT);
+      }
     }
 
     return MEMCACHED_SUCCESS;
   }
 
-  ssize_t sent_length= memcached_io_writev(instance, vector, count, with_flush);
-  size_t command_length= 0;
-  for (uint32_t x= 0; x < count; ++x, vector++)
-  {
-    command_length+= vector->length;
-  }
-
-  if (sent_length == -1 or size_t(sent_length) != command_length)
+  bool sent_success= memcached_io_writev(instance, vector, count, with_flush);
+  if (sent_success == false)
   {
-    rc= MEMCACHED_WRITE_FAILURE;
-    WATCHPOINT_ERROR(rc);
-    WATCHPOINT_ERRNO(errno);
+    if (memcached_last_error(instance->root) == MEMCACHED_SUCCESS)
+    {
+      return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
+    }
+    else
+    {
+      rc= MEMCACHED_WRITE_FAILURE;
+    }
   }
   else if (memcached_is_replying(instance->root))
   {