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_do(memcached_server_write_instance_st ptr
, const void *command
,
15 size_t command_length
, bool with_flush
)
17 assert_msg(command_length
, "Programming error, somehow a command had a length of zero");
18 assert_msg(command
, "Programming error, somehow a command was NULL");
20 memcached_return_t rc
;
21 if (memcached_failed(rc
= memcached_connect(ptr
)))
23 WATCHPOINT_ASSERT(rc
== memcached_last_error(ptr
->root
));
29 ** Since non buffering ops in UDP mode dont check to make sure they will fit
30 ** before they start writing, if there is any data in buffer, clear it out,
31 ** otherwise we might get a partial write.
33 if (memcached_is_udp(ptr
->root
) and with_flush
and ptr
->write_buffer_offset
> UDP_DATAGRAM_HEADER_LENGTH
)
35 memcached_io_write(ptr
, NULL
, 0, true);
38 ssize_t sent_length
= memcached_io_write(ptr
, command
, command_length
, with_flush
);
40 if (sent_length
== -1 or size_t(sent_length
) != command_length
)
42 rc
= MEMCACHED_WRITE_FAILURE
;
44 else if ((ptr
->root
->flags
.no_reply
) == 0)
46 memcached_server_response_increment(ptr
);
52 memcached_return_t
memcached_vdo(memcached_server_write_instance_st ptr
,
53 const struct libmemcached_io_vector_st
*vector
, size_t count
,
56 memcached_return_t rc
;
58 WATCHPOINT_ASSERT(count
);
59 WATCHPOINT_ASSERT(vector
);
61 if (memcached_failed(rc
= memcached_connect(ptr
)))
64 assert_msg(ptr
->error_messages
, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
69 ** Since non buffering ops in UDP mode dont check to make sure they will fit
70 ** before they start writing, if there is any data in buffer, clear it out,
71 ** otherwise we might get a partial write.
73 if (memcached_is_udp(ptr
->root
) and with_flush
and ptr
->write_buffer_offset
> UDP_DATAGRAM_HEADER_LENGTH
)
75 if (memcached_io_write(ptr
, NULL
, 0, true) == -1)
77 memcached_io_reset(ptr
);
78 return memcached_set_error(*ptr
, MEMCACHED_WRITE_FAILURE
, MEMCACHED_AT
);
82 ssize_t sent_length
= memcached_io_writev(ptr
, vector
, count
, with_flush
);
84 size_t command_length
= 0;
85 for (uint32_t x
= 0; x
< count
; ++x
, vector
++)
87 command_length
+= vector
->length
;
90 if (sent_length
== -1 or size_t(sent_length
) != command_length
)
92 rc
= MEMCACHED_WRITE_FAILURE
;
94 WATCHPOINT_ERRNO(errno
);
96 else if ((ptr
->root
->flags
.no_reply
) == 0)
98 memcached_server_response_increment(ptr
);