From: Brian Aker Date: Mon, 21 May 2012 07:09:19 +0000 (-0400) Subject: Update writev X-Git-Tag: 1.0.8~2^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=bcf4f7d33fd0b0cb5bb599b300aa043effc62a33;p=m6w6%2Flibmemcached Update writev --- diff --git a/libmemcached/do.cc b/libmemcached/do.cc index 2ce64483..61a143b8 100644 --- a/libmemcached/do.cc +++ b/libmemcached/do.cc @@ -72,14 +72,8 @@ memcached_return_t memcached_vdo(memcached_server_write_instance_st instance, return MEMCACHED_SUCCESS; } - 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 or size_t(sent_length) != command_length) + bool sent_success= memcached_io_writev(instance, vector, count, with_flush); + if (sent_success == false) { if (memcached_last_error(instance->root) == MEMCACHED_SUCCESS) { diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 1deb3976..7356bbc3 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -310,7 +310,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, } hosts_connected++; - if ((memcached_io_writev(instance, vector, 4, false)) == -1) + if ((memcached_io_writev(instance, vector, 4, false)) == false) { failures_occured_in_sending= true; continue; @@ -321,7 +321,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, } else { - if ((memcached_io_writev(instance, (vector + 1), 3, false)) == -1) + if ((memcached_io_writev(instance, (vector + 1), 3, false)) == false) { memcached_server_response_reset(instance); failures_occured_in_sending= true; @@ -518,7 +518,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, { keys[x], key_length[x] } }; - if (memcached_io_writev(instance, vector, 3, flush) == -1) + if (memcached_io_writev(instance, vector, 3, flush) == false) { memcached_server_response_reset(instance); rc= MEMCACHED_SOME_ERRORS; @@ -651,7 +651,7 @@ static memcached_return_t replication_binary_mget(memcached_st *ptr, { keys[x], key_length[x] } }; - if (memcached_io_writev(instance, vector, 3, true) == -1) + if (memcached_io_writev(instance, vector, 3, true) == false) { memcached_io_reset(instance); dead_servers[server]= true; diff --git a/libmemcached/io.cc b/libmemcached/io.cc index d0e6aaf6..885e2391 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -531,9 +531,9 @@ memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr) /* fall through */ case ENOTCONN: // Programmer Error - WATCHPOINT_ASSERT(0); + assert(0); case ENOTSOCK: - WATCHPOINT_ASSERT(0); + assert(0); case EBADF: assert_msg(ptr->fd != INVALID_SOCKET, "Invalid socket state"); case EINVAL: @@ -620,20 +620,22 @@ ssize_t memcached_io_write(memcached_server_write_instance_st ptr, return ssize_t(written); } -ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, +bool memcached_io_writev(memcached_server_write_instance_st ptr, libmemcached_io_vector_st vector[], const size_t number_of, const bool with_flush) { + ssize_t complete_total= 0; ssize_t total= 0; for (size_t x= 0; x < number_of; x++, vector++) { + complete_total+= vector->length; if (vector->length) { size_t written; if ((_io_write(ptr, vector->buffer, vector->length, false, written)) == false) { - return -1; + return false; } total+= written; } @@ -643,11 +645,11 @@ ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, { if (memcached_io_write(ptr) == false) { - return -1; + return false; } } - return total; + return (complete_total == total); } diff --git a/libmemcached/io.hpp b/libmemcached/io.hpp index 549f86a0..ce9cef51 100644 --- a/libmemcached/io.hpp +++ b/libmemcached/io.hpp @@ -43,9 +43,9 @@ bool memcached_io_write(memcached_server_write_instance_st ptr); ssize_t memcached_io_write(memcached_server_write_instance_st ptr, const void *buffer, size_t length, bool with_flush); -ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, - libmemcached_io_vector_st vector[], - const size_t number_of, const bool with_flush); +bool memcached_io_writev(memcached_server_write_instance_st ptr, + libmemcached_io_vector_st vector[], + const size_t number_of, const bool with_flush); memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr); diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 40d37e3a..7e0e50d6 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -240,7 +240,7 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s { data, len } }; - if (memcached_io_writev(server, vector, 3, true) == -1) + if (memcached_io_writev(server, vector, 3, true) == false) { rc= MEMCACHED_WRITE_FAILURE; break;