Style change
[m6w6/libmemcached] / libmemcached / do.cc
1 /* LibMemcached
2 * Copyright (C) 2006-2010 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary:
9 *
10 */
11
12 #include <libmemcached/common.h>
13
14 memcached_return_t memcached_vdo(memcached_server_write_instance_st instance,
15 libmemcached_io_vector_st *vector,
16 const size_t count,
17 const bool with_flush)
18 {
19 memcached_return_t rc;
20
21 WATCHPOINT_ASSERT(count);
22 WATCHPOINT_ASSERT(vector);
23
24 if (memcached_failed(rc= memcached_connect(instance)))
25 {
26 WATCHPOINT_ERROR(rc);
27 assert_msg(instance->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
28 return rc;
29 }
30
31 /*
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.
35 **/
36 if (memcached_is_udp(instance->root))
37 {
38 size_t write_length= io_vector_total_size(vector, 11) +UDP_DATAGRAM_HEADER_LENGTH;
39
40 if (write_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
41 {
42 return MEMCACHED_WRITE_FAILURE;
43 }
44
45 return MEMCACHED_NOT_SUPPORTED;
46 }
47
48 ssize_t sent_length= memcached_io_writev(instance, vector, count, with_flush);
49 size_t command_length= 0;
50 for (uint32_t x= 0; x < count; ++x, vector++)
51 {
52 command_length+= vector->length;
53 }
54
55 if (sent_length == -1 or size_t(sent_length) != command_length)
56 {
57 rc= MEMCACHED_WRITE_FAILURE;
58 WATCHPOINT_ERROR(rc);
59 WATCHPOINT_ERRNO(errno);
60 }
61 else if (memcached_is_replying(instance->root))
62 {
63 memcached_server_response_increment(instance);
64 }
65
66 return rc;
67 }