X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fdo.cc;h=a51472ba66562a50a18353b1c843bd5c3a3afd7c;hb=092fc74b65236e6ef2c6f9f1cacf23e6c84d3071;hp=854c611497c36b60a2286450cbb2b05f75861a54;hpb=805884743f76a5c4dad8ad20e6033630a92e71df;p=awesomized%2Flibmemcached diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 854c6114..a51472ba 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -11,19 +11,20 @@ #include -memcached_return_t memcached_do(memcached_server_write_instance_st ptr, const void *command, - size_t command_length, bool with_flush) +memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, + libmemcached_io_vector_st *vector, + const size_t count, + const bool with_flush) { memcached_return_t rc; - ssize_t sent_length; - WATCHPOINT_ASSERT(command_length); - WATCHPOINT_ASSERT(command); + WATCHPOINT_ASSERT(count); + WATCHPOINT_ASSERT(vector); - if (memcached_failed(rc= memcached_connect(ptr))) + if (memcached_failed(rc= memcached_connect(instance))) { - WATCHPOINT_ASSERT(rc == memcached_last_error(ptr->root)); WATCHPOINT_ERROR(rc); + assert_msg(instance->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none."); return rc; } @@ -32,68 +33,40 @@ memcached_return_t memcached_do(memcached_server_write_instance_st ptr, const vo ** 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) + if (memcached_is_udp(instance->root)) { - memcached_io_write(ptr, NULL, 0, true); - } + if (vector->buffer or vector->length) + { + return memcached_set_error(*instance->root, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT, + memcached_literal_param("UDP messages was attempted, but vector was not setup for it")); + } - sent_length= memcached_io_write(ptr, command, command_length, with_flush); + size_t write_length= io_vector_total_size(vector, 11) +UDP_DATAGRAM_HEADER_LENGTH; - 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); - } + if (write_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH) + { + return MEMCACHED_WRITE_FAILURE; + } - return rc; -} - -memcached_return_t memcached_vdo(memcached_server_write_instance_st ptr, - const struct libmemcached_io_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); + return MEMCACHED_NOT_SUPPORTED; } - sent_length= memcached_io_writev(ptr, vector, count, with_flush); - + ssize_t sent_length= memcached_io_writev(instance, 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) + if (sent_length == -1 or size_t(sent_length) != command_length) { rc= MEMCACHED_WRITE_FAILURE; WATCHPOINT_ERROR(rc); WATCHPOINT_ERRNO(errno); } - else if ((ptr->root->flags.no_reply) == 0) + else if (memcached_is_replying(instance->root)) { - memcached_server_response_increment(ptr); + memcached_server_response_increment(instance); } return rc;