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 static memcached_return_t
_vdo_udp(memcached_instance_st
* instance
,
15 libmemcached_io_vector_st vector
[],
19 if (vector
[0].buffer
or vector
[0].length
)
21 return memcached_set_error(*instance
->root
, MEMCACHED_NOT_SUPPORTED
, MEMCACHED_AT
,
22 memcached_literal_param("UDP messages was attempted, but vector was not setup for it"));
26 memset(&msg
, 0, sizeof(msg
));
28 increment_udp_message_id(instance
);
29 vector
[0].buffer
= instance
->write_buffer
;
30 vector
[0].length
= UDP_DATAGRAM_HEADER_LENGTH
;
32 msg
.msg_iov
= (struct iovec
*)vector
;
34 msg
.msg_iovlen
= int(count
);
36 msg
.msg_iovlen
= count
;
42 ssize_t sendmsg_length
= ::sendmsg(instance
->fd
, &msg
, 0);
43 if (sendmsg_length
> 0)
47 else if (sendmsg_length
< 0)
49 if (errno
== EMSGSIZE
)
51 return memcached_set_error(*instance
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
54 return memcached_set_errno(*instance
, errno
, MEMCACHED_AT
);
58 return MEMCACHED_SUCCESS
;
63 return MEMCACHED_FAILURE
;
67 memcached_return_t
memcached_vdo(memcached_instance_st
* instance
,
68 libmemcached_io_vector_st vector
[],
70 const bool with_flush
)
72 memcached_return_t rc
;
74 assert_msg(vector
, "Invalid vector passed");
76 if (memcached_failed(rc
= memcached_connect(instance
)))
79 assert_msg(instance
->error_messages
, "memcached_connect() returned an error but the Instance showed none.");
84 ** Since non buffering ops in UDP mode dont check to make sure they will fit
85 ** before they start writing, if there is any data in buffer, clear it out,
86 ** otherwise we might get a partial write.
88 if (memcached_is_udp(instance
->root
))
90 return _vdo_udp(instance
, vector
, count
);
93 bool sent_success
= memcached_io_writev(instance
, vector
, count
, with_flush
);
94 if (sent_success
== false)
96 assert(memcached_last_error(instance
->root
) == MEMCACHED_SUCCESS
);
97 if (memcached_last_error(instance
->root
) == MEMCACHED_SUCCESS
)
99 assert(memcached_last_error(instance
->root
) != MEMCACHED_SUCCESS
);
100 return memcached_set_error(*instance
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
104 rc
= memcached_last_error(instance
->root
);
107 else if (memcached_is_replying(instance
->root
))
109 memcached_server_response_increment(instance
);