2 * Copyright (C) 2006-2010 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
12 #include <libmemcached/common.h>
14 memcached_return_t
memcached_vdo(org::libmemcached::Instance
* instance
,
15 libmemcached_io_vector_st vector
[],
17 const bool with_flush
)
19 memcached_return_t rc
;
21 assert_msg(vector
, "Invalid vector passed");
23 if (memcached_failed(rc
= memcached_connect(instance
)))
26 assert_msg(instance
->error_messages
, "memcached_connect() returned an error but the Instance showed none.");
31 ** Since non buffering ops in UDP mode dont check to make sure they will fit
32 ** before they start writing, if there is any data in buffer, clear it out,
33 ** otherwise we might get a partial write.
35 if (memcached_is_udp(instance
->root
))
37 if (vector
[0].buffer
or vector
[0].length
)
39 return memcached_set_error(*instance
->root
, MEMCACHED_NOT_SUPPORTED
, MEMCACHED_AT
,
40 memcached_literal_param("UDP messages was attempted, but vector was not setup for it"));
44 memset(&msg
, 0, sizeof(msg
));
46 increment_udp_message_id(instance
);
47 vector
[0].buffer
= instance
->write_buffer
;
48 vector
[0].length
= UDP_DATAGRAM_HEADER_LENGTH
;
50 msg
.msg_iov
= (struct iovec
*)vector
;
51 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
52 msg
.msg_iovlen
= int(count
);
54 msg
.msg_iovlen
= count
;
60 ssize_t sendmsg_length
= ::sendmsg(instance
->fd
, &msg
, 0);
61 if (sendmsg_length
> 0)
65 else if (sendmsg_length
< 0)
67 if (errno
== EMSGSIZE
)
69 return memcached_set_error(*instance
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
72 return memcached_set_errno(*instance
, errno
, MEMCACHED_AT
);
76 return MEMCACHED_SUCCESS
;
79 bool sent_success
= memcached_io_writev(instance
, vector
, count
, with_flush
);
80 if (sent_success
== false)
82 if (memcached_last_error(instance
->root
) == MEMCACHED_SUCCESS
)
84 return memcached_set_error(*instance
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
88 rc
= MEMCACHED_WRITE_FAILURE
;
91 else if (memcached_is_replying(instance
->root
))
93 memcached_server_response_increment(instance
);