#include <libmemcached/common.h>
-memcached_return_t memcached_vdo(org::libmemcached::Instance* instance,
+static memcached_return_t _vdo_udp(memcached_instance_st* instance,
+ libmemcached_io_vector_st vector[],
+ const size_t count)
+{
+#ifndef __MINGW32__
+ if (vector[0].buffer or vector[0].length)
+ {
+ return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT,
+ memcached_literal_param("UDP messages was attempted, but vector was not setup for it"));
+ }
+
+ struct msghdr msg;
+ memset(&msg, 0, sizeof(msg));
+
+ increment_udp_message_id(instance);
+ vector[0].buffer= instance->write_buffer;
+ vector[0].length= UDP_DATAGRAM_HEADER_LENGTH;
+
+ msg.msg_iov= (struct iovec*)vector;
+#ifdef __APPLE__
+ msg.msg_iovlen= int(count);
+#else
+ msg.msg_iovlen= count;
+#endif
+
+ uint32_t retry= 5;
+ while (--retry)
+ {
+ 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;
+#else
+ (void)instance;
+ (void)vector;
+ (void)count;
+ return MEMCACHED_FAILURE;
+#endif
+}
+
+memcached_return_t memcached_vdo(memcached_instance_st* instance,
libmemcached_io_vector_st vector[],
const size_t count,
const bool with_flush)
** 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))
{
-#ifndef __MINGW32__
- if (vector[0].buffer or vector[0].length)
- {
- return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT,
- memcached_literal_param("UDP messages was attempted, but vector was not setup for it"));
- }
-
- struct msghdr msg;
- memset(&msg, 0, sizeof(msg));
-
- increment_udp_message_id(instance);
- vector[0].buffer= instance->write_buffer;
- vector[0].length= UDP_DATAGRAM_HEADER_LENGTH;
-
- msg.msg_iov= (struct iovec*)vector;
-#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
- msg.msg_iovlen= int(count);
-#else
- msg.msg_iovlen= count;
-#endif
-
- uint32_t retry= 5;
- while (--retry)
- {
- 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;
-#else
- return MEMCACHED_FAILURE;
-#endif
+ 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)
{
- if (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_WRITE_FAILURE;
+ 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);
}