Fixed return length issues.
author <brian@gir.tangent.org> <>
Sat, 27 Oct 2007 02:08:04 +0000 (19:08 -0700)
committer <brian@gir.tangent.org> <>
Sat, 27 Oct 2007 02:08:04 +0000 (19:08 -0700)
Moved to using read() to see if I can trap problems reported for dead
memcached servers.

THANKS [new file with mode: 0644]
lib/memcached_io.c

diff --git a/THANKS b/THANKS
new file mode 100644 (file)
index 0000000..41f271d
--- /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
index 54a0e8cc9612eb5c0d66a274fa8a3a763e324e26..49f6bc686362b70788f3611a091ffe4a52d55d42 100644 (file)
@@ -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;
 }
 
 /*