From: Date: Sat, 27 Oct 2007 02:08:04 +0000 (-0700) Subject: Fixed return length issues. X-Git-Tag: 0.7~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1bd637f6eccc1064a4e19e40b14a340818d1ccf3;p=awesomized%2Flibmemcached Fixed return length issues. Moved to using read() to see if I can trap problems reported for dead memcached servers. --- diff --git a/THANKS b/THANKS new file mode 100644 index 00000000..41f271d0 --- /dev/null +++ b/THANKS @@ -0,0 +1,4 @@ +Eirik A. Nygaard - IO Patch +Cal Heldenbrand - Awesome feedback on performance +Dustin Sallings - Insight into protocol +Tobias Luetke - Performance Feedback diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 54a0e8cc..49f6bc68 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -51,9 +51,9 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, return -1; } - data_read= recv(ptr->hosts[server_key].fd, + data_read= read(ptr->hosts[server_key].fd, ptr->read_buffer, - MEMCACHED_MAX_BUFFER, 0); + MEMCACHED_MAX_BUFFER); if (data_read == -1) { switch (errno) @@ -119,6 +119,7 @@ ssize_t memcached_io_write(memcached_st *ptr, unsigned int server_key, ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) { size_t sent_length; + size_t return_length; char *write_ptr= ptr->write_buffer; size_t write_length= ptr->write_buffer_offset; unsigned int loop= 1; @@ -126,6 +127,7 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) if (ptr->write_buffer_offset == 0) return 0; + return_length= 0; while (write_length) { if (ptr->flags & MEM_NO_BLOCK) @@ -138,14 +140,16 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) } sent_length= 0; - if ((sent_length= write(ptr->hosts[server_key].fd, write_ptr, - write_length)) == -1) + if ((ssize_t)(sent_length= write(ptr->hosts[server_key].fd, write_ptr, + write_length)) == -1) { switch (errno) { case ENOBUFS: case EAGAIN: - if (loop < 10) + WATCHPOINT; + continue; + if (loop < 100) { loop++; break; @@ -156,16 +160,17 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) return -1; } } - else - { - write_ptr+= sent_length; - write_length-= sent_length; - } + + write_ptr+= sent_length; + write_length-= sent_length; + return_length+= sent_length; } + WATCHPOINT_ASSERT(write_length == 0); + WATCHPOINT_ASSERT(return_length == ptr->write_buffer_offset); ptr->write_buffer_offset= 0; - return sent_length; + return return_length; } /*