From: Brian Aker Date: Fri, 2 Apr 2010 04:17:58 +0000 (-0700) Subject: Moved to using vector send for writes (lowers function call count). X-Git-Tag: 0.40~24 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=54915965dc90f7aeceda9e9b1370c77eb8b1631f;p=awesomized%2Flibmemcached Moved to using vector send for writes (lowers function call count). --- diff --git a/libmemcached/io.c b/libmemcached/io.c index c72aaa27..616ad497 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -326,36 +326,8 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, return MEMCACHED_SUCCESS; } -ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, - struct __write_vector_st *vector, - size_t number_of, bool with_flush) -{ - ssize_t total= 0; - - for (size_t x= 0; x < number_of; x++, vector++) - { - ssize_t returnable; - - if ((returnable= memcached_io_write(ptr, vector->buffer, vector->length, false)) == -1) - { - return -1; - } - total+= returnable; - } - - if (with_flush) - { - if (memcached_io_write(ptr, NULL, 0, true) == -1) - { - return -1; - } - } - - return total; -} - -ssize_t memcached_io_write(memcached_server_write_instance_st ptr, - const void *buffer, size_t length, bool with_flush) +static ssize_t _io_write(memcached_server_write_instance_st ptr, + const void *buffer, size_t length, bool with_flush) { size_t original_length; const char* buffer_ptr; @@ -431,6 +403,41 @@ ssize_t memcached_io_write(memcached_server_write_instance_st ptr, return (ssize_t) original_length; } +ssize_t memcached_io_write(memcached_server_write_instance_st ptr, + const void *buffer, size_t length, bool with_flush) +{ + return _io_write(ptr, buffer, length, with_flush); +} + +ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, + const struct __write_vector_st *vector, + size_t number_of, bool with_flush) +{ + ssize_t total= 0; + + for (size_t x= 0; x < number_of; x++, vector++) + { + ssize_t returnable; + + if ((returnable= _io_write(ptr, vector->buffer, vector->length, false)) == -1) + { + return -1; + } + total+= returnable; + } + + if (with_flush) + { + if (memcached_io_write(ptr, NULL, 0, true) == -1) + { + return -1; + } + } + + return total; +} + + memcached_return_t memcached_io_close(memcached_server_write_instance_st ptr) { if (ptr->fd == -1) diff --git a/libmemcached/io.h b/libmemcached/io.h index 89f3d477..b614d818 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -49,7 +49,7 @@ struct __write_vector_st LIBMEMCACHED_LOCAL ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, - struct __write_vector_st *vector, + const struct __write_vector_st *vector, size_t number_of, bool with_flush); LIBMEMCACHED_LOCAL