From: Brian Aker Date: Tue, 2 Oct 2007 01:49:12 +0000 (-0700) Subject: Optimization for read(), we now optimize on buffer size. X-Git-Tag: 0.4~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=81be4de01a86e73b9222f7e92d0a6f7476029864;p=m6w6%2Flibmemcached Optimization for read(), we now optimize on buffer size. --- diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 77df4319..8615aa6e 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -17,10 +17,29 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, { if (!ptr->read_buffer_length) { - ptr->read_buffer_length= recv(ptr->hosts[server_key].fd, - ptr->read_buffer, - MEMCACHED_MAX_BUFFER, 0); - ptr->read_ptr= ptr->read_buffer; + if (length > 1) + { + + size_t data_read; + data_read= recv(ptr->hosts[server_key].fd, + buffer_ptr, + length - x, 0); + if (data_read == -1) + return -1; + if (data_read == 0) + return x; + + data_read+= x; + + return data_read; + } + else + { + ptr->read_buffer_length= recv(ptr->hosts[server_key].fd, + ptr->read_buffer, + MEMCACHED_MAX_BUFFER, 0); + ptr->read_ptr= ptr->read_buffer; + } if (ptr->read_buffer_length == -1) return -1;