X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fdo.c;h=1a274cd336ef4d4f9baee3718c4e237086c1f944;hb=09ef521d2c88955d04d6c91f7b5a1671a1955130;hp=fa33f51ec30122cb521b47971802e54b58726cf2;hpb=9b767485048053ad0b4c2897a0d3784aa6e9fe10;p=awesomized%2Flibmemcached diff --git a/libmemcached/do.c b/libmemcached/do.c index fa33f51e..1a274cd3 100644 --- a/libmemcached/do.c +++ b/libmemcached/do.c @@ -1,7 +1,18 @@ +/* LibMemcached + * Copyright (C) 2006-2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: + * + */ + #include "common.h" -memcached_return_t memcached_do(memcached_server_st *ptr, const void *command, - size_t command_length, uint8_t with_flush) +memcached_return_t memcached_do(memcached_server_write_instance_st ptr, const void *command, + size_t command_length, bool with_flush) { memcached_return_t rc; ssize_t sent_length; @@ -21,14 +32,68 @@ memcached_return_t memcached_do(memcached_server_st *ptr, const void *command, ** otherwise we might get a partial write. **/ if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH) + { memcached_io_write(ptr, NULL, 0, true); + } - sent_length= memcached_io_write(ptr, command, command_length, (bool) with_flush); + sent_length= memcached_io_write(ptr, command, command_length, with_flush); if (sent_length == -1 || (size_t)sent_length != command_length) + { rc= MEMCACHED_WRITE_FAILURE; + } else if ((ptr->root->flags.no_reply) == 0) + { memcached_server_response_increment(ptr); + } + + return rc; +} + +memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr, + const struct __write_vector_st *vector, size_t count, + bool with_flush) +{ + memcached_return_t rc; + ssize_t sent_length; + + WATCHPOINT_ASSERT(count); + WATCHPOINT_ASSERT(vector); + + if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS) + { + WATCHPOINT_ERROR(rc); + return rc; + } + + /* + ** Since non buffering ops in UDP mode dont check to make sure they will fit + ** before they start writing, if there is any data in buffer, clear it out, + ** otherwise we might get a partial write. + **/ + if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH) + { + memcached_io_write(ptr, NULL, 0, true); + } + + sent_length= memcached_io_writev(ptr, vector, count, with_flush); + + size_t command_length= 0; + for (uint32_t x= 0; x < count; ++x, vector++) + { + command_length+= vector->length; + } + + if (sent_length == -1 || (size_t)sent_length != command_length) + { + rc= MEMCACHED_WRITE_FAILURE; + WATCHPOINT_ERROR(rc); + WATCHPOINT_ERRNO(errno); + } + else if ((ptr->root->flags.no_reply) == 0) + { + memcached_server_response_increment(ptr); + } return rc; }