First merge of Trond's patches (cherry picking).
[m6w6/libmemcached] / libmemcached / memcached_do.c
1 #include "common.h"
2
3 memcached_return_t memcached_do(memcached_server_st *ptr, const void *command,
4 size_t command_length, uint8_t with_flush)
5 {
6 memcached_return_t rc;
7 ssize_t sent_length;
8
9 WATCHPOINT_ASSERT(command_length);
10 WATCHPOINT_ASSERT(command);
11
12 if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
13 {
14 WATCHPOINT_ERROR(rc);
15 return rc;
16 }
17
18 /*
19 ** Since non buffering ops in UDP mode dont check to make sure they will fit
20 ** before they start writing, if there is any data in buffer, clear it out,
21 ** otherwise we might get a partial write.
22 **/
23 if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH)
24 memcached_io_write(ptr, NULL, 0, 1);
25
26 sent_length= memcached_io_write(ptr, command, command_length, (char) with_flush);
27
28 if (sent_length == -1 || (size_t)sent_length != command_length)
29 rc= MEMCACHED_WRITE_FAILURE;
30 else if ((ptr->root->flags.no_reply) == 0)
31 memcached_server_response_increment(ptr);
32
33 return rc;
34 }