X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fdo.cc;h=db533680f77193f80ea3dd6ce37eb65bcb1f3639;hb=5274cc277f4a1216a7d566d2bb164c80e0d44d43;hp=3c3519c27b9cccb29df440a9e4719735bb3be424;hpb=324548f9250e1c0ad5814f1436e401ad989c84f3;p=awesomized%2Flibmemcached diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 3c3519c2..db533680 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -11,7 +11,7 @@ #include -memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, +memcached_return_t memcached_vdo(org::libmemcached::Instance* instance, libmemcached_io_vector_st vector[], const size_t count, const bool with_flush) @@ -23,7 +23,7 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, if (memcached_failed(rc= memcached_connect(instance))) { WATCHPOINT_ERROR(rc); - assert_msg(instance->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none."); + assert_msg(instance->error_messages, "memcached_connect() returned an error but the Instance showed none."); return rc; } @@ -48,28 +48,45 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, 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 - 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)) {