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(memcached_server_write_instance_st ptr
,
15 const struct libmemcached_io_vector_st
*vector
,
17 const bool with_flush
)
19 memcached_return_t rc
;
21 WATCHPOINT_ASSERT(count
);
22 WATCHPOINT_ASSERT(vector
);
24 if (memcached_failed(rc
= memcached_connect(ptr
)))
27 assert_msg(ptr
->error_messages
, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
32 ** Since non buffering ops in UDP mode dont check to make sure they will fit
33 ** before they start writing, if there is any data in buffer, clear it out,
34 ** otherwise we might get a partial write.
36 if (memcached_is_udp(ptr
->root
) and with_flush
and ptr
->write_buffer_offset
> UDP_DATAGRAM_HEADER_LENGTH
)
38 if (memcached_io_write(ptr
, NULL
, 0, true) == -1)
40 memcached_io_reset(ptr
);
41 return memcached_set_error(*ptr
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
45 ssize_t sent_length
= memcached_io_writev(ptr
, vector
, count
, with_flush
);
47 size_t command_length
= 0;
48 for (uint32_t x
= 0; x
< count
; ++x
, vector
++)
50 command_length
+= vector
->length
;
53 if (sent_length
== -1 or size_t(sent_length
) != command_length
)
55 rc
= MEMCACHED_WRITE_FAILURE
;
57 WATCHPOINT_ERRNO(errno
);
59 else if ((ptr
->root
->flags
.no_reply
) == 0)
61 memcached_server_response_increment(ptr
);