More Cleanup
[m6w6/libmemcached] / libmemcached / do.c
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 "common.h"
13
14 memcached_return_t memcached_do(memcached_server_st *ptr, const void *command,
15 size_t command_length, bool with_flush)
16 {
17 memcached_return_t rc;
18 ssize_t sent_length;
19
20 WATCHPOINT_ASSERT(command_length);
21 WATCHPOINT_ASSERT(command);
22
23 if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
24 {
25 WATCHPOINT_ERROR(rc);
26 return rc;
27 }
28
29 /*
30 ** Since non buffering ops in UDP mode dont check to make sure they will fit
31 ** before they start writing, if there is any data in buffer, clear it out,
32 ** otherwise we might get a partial write.
33 **/
34 if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
35 memcached_io_write(ptr, NULL, 0, true);
36
37 sent_length= memcached_io_write(ptr, command, command_length, with_flush);
38
39 if (sent_length == -1 || (size_t)sent_length != command_length)
40 rc= MEMCACHED_WRITE_FAILURE;
41 else if ((ptr->root->flags.no_reply) == 0)
42 memcached_server_response_increment(ptr);
43
44 return rc;
45 }