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 memcached_return_t rc
;
20 WATCHPOINT_ASSERT(command_length
);
21 WATCHPOINT_ASSERT(command
);
23 if (memcached_failed(rc
= memcached_connect(ptr
)))
25 WATCHPOINT_ASSERT(rc
== memcached_last_error(ptr
->root
));
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 (ptr
->type
== MEMCACHED_CONNECTION_UDP
&& with_flush
&& ptr
->write_buffer_offset
> UDP_DATAGRAM_HEADER_LENGTH
)
37 memcached_io_write(ptr
, NULL
, 0, true);
40 sent_length
= memcached_io_write(ptr
, command
, command_length
, with_flush
);
42 if (sent_length
== -1 || (size_t)sent_length
!= command_length
)
44 rc
= MEMCACHED_WRITE_FAILURE
;
46 else if ((ptr
->root
->flags
.no_reply
) == 0)
48 memcached_server_response_increment(ptr
);
54 memcached_return_t
memcached_vdo(memcached_server_write_instance_st ptr
,
55 const struct libmemcached_io_vector_st
*vector
, size_t count
,
58 memcached_return_t rc
;
61 WATCHPOINT_ASSERT(count
);
62 WATCHPOINT_ASSERT(vector
);
64 if (memcached_failed(rc
= memcached_connect(ptr
)))
67 assert_msg(ptr
->error_messages
, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
72 ** Since non buffering ops in UDP mode dont check to make sure they will fit
73 ** before they start writing, if there is any data in buffer, clear it out,
74 ** otherwise we might get a partial write.
76 if (ptr
->type
== MEMCACHED_CONNECTION_UDP
&& with_flush
&& ptr
->write_buffer_offset
> UDP_DATAGRAM_HEADER_LENGTH
)
78 memcached_io_write(ptr
, NULL
, 0, true);
81 sent_length
= memcached_io_writev(ptr
, vector
, count
, with_flush
);
83 size_t command_length
= 0;
84 for (uint32_t x
= 0; x
< count
; ++x
, vector
++)
86 command_length
+= vector
->length
;
89 if (sent_length
== -1 or size_t(sent_length
) != command_length
)
91 rc
= MEMCACHED_WRITE_FAILURE
;
93 WATCHPOINT_ERRNO(errno
);
95 else if ((ptr
->root
->flags
.no_reply
) == 0)
97 memcached_server_response_increment(ptr
);