attempt to fix #12, #49 and #65
[awesomized/libmemcached] / libmemcached / do.cc
index ef63927b55e01fd294bfc4c91ff3869a58250acb..59f9d5a3ada657c68d74da26837e5d90212fde30 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <libmemcached/common.h>
 
-static memcached_return_t _vdo_udp(org::libmemcached::Instance* instance,
+static memcached_return_t _vdo_udp(memcached_instance_st* instance,
                                    libmemcached_io_vector_st vector[],
                                    const size_t count)
 {
@@ -30,7 +30,7 @@ static memcached_return_t _vdo_udp(org::libmemcached::Instance* instance,
   vector[0].length= UDP_DATAGRAM_HEADER_LENGTH;
 
   msg.msg_iov= (struct iovec*)vector;
-#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+#ifdef __APPLE__
   msg.msg_iovlen= int(count);
 #else
   msg.msg_iovlen= count;
@@ -57,11 +57,14 @@ static memcached_return_t _vdo_udp(org::libmemcached::Instance* instance,
 
   return MEMCACHED_SUCCESS;
 #else
+  (void)instance;
+  (void)vector;
+  (void)count;
   return MEMCACHED_FAILURE;
 #endif
 }
 
-memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
+memcached_return_t memcached_vdo(memcached_instance_st* instance,
                                  libmemcached_io_vector_st vector[],
                                  const size_t count,
                                  const bool with_flush)
@@ -82,26 +85,23 @@ memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
   ** before they start writing, if there is any data in buffer, clear it out,
   ** otherwise we might get a partial write.
   **/
+  bool sent_success;
   if (memcached_is_udp(instance->root))
   {
-    return _vdo_udp(instance, vector, count);
+    sent_success= memcached_success(rc= _vdo_udp(instance, vector, count));
+  } else {
+    sent_success= memcached_io_writev(instance, vector, count, with_flush);
   }
-
-  bool sent_success= memcached_io_writev(instance, vector, count, with_flush);
   if (sent_success == false)
   {
-    assert(memcached_last_error(instance->root) == MEMCACHED_SUCCESS);
-    if (memcached_last_error(instance->root) == MEMCACHED_SUCCESS)
-    {
-      assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS);
-      return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
-    }
-    else
+    rc= memcached_last_error(instance->root);
+    if (rc == MEMCACHED_SUCCESS)
     {
-      rc= memcached_last_error(instance->root);
+      memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT);
     }
+    memcached_io_reset(instance);
   }
-  else if (memcached_is_replying(instance->root))
+  else if (memcached_is_replying(instance->root) && !memcached_is_udp(instance->root))
   {
     memcached_server_response_increment(instance);
   }