X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_do.c;h=d673f187149413b858014e0b91c67aebe52d2c4c;hb=b4de8d3fd063b9017797dd9809ab3acb8a537606;hp=c4bf574f641d8a28d36ce649db884bc20d913c74;hpb=1d7f999b7d38db3308a0533a83fea23987fb0178;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached_do.c b/libmemcached/memcached_do.c index c4bf574f..d673f187 100644 --- a/libmemcached/memcached_do.c +++ b/libmemcached/memcached_do.c @@ -1,22 +1,33 @@ #include "common.h" -memcached_return memcached_do(memcached_server_st *ptr, char *command, - size_t command_length, uint8_t with_flush) +memcached_return_t memcached_do(memcached_server_st *ptr, const void *command, + size_t command_length, uint8_t with_flush) { - memcached_return rc; + memcached_return_t rc; ssize_t sent_length; WATCHPOINT_ASSERT(command_length); WATCHPOINT_ASSERT(command); if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS) + { + WATCHPOINT_ERROR(rc); return rc; + } - sent_length= memcached_io_write(ptr, command, command_length, with_flush); + /* + ** 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, 1); - if (sent_length == -1 || sent_length != command_length) + sent_length= memcached_io_write(ptr, command, command_length, (char) with_flush); + + if (sent_length == -1 || (size_t)sent_length != command_length) rc= MEMCACHED_WRITE_FAILURE; - else + else if ((ptr->root->flags.no_reply) == 0) memcached_server_response_increment(ptr); return rc;