Optimization for read(), we now optimize on buffer size.
authorBrian Aker <brian@tangent.org>
Tue, 2 Oct 2007 01:49:12 +0000 (18:49 -0700)
committerBrian Aker <brian@tangent.org>
Tue, 2 Oct 2007 01:49:12 +0000 (18:49 -0700)
lib/memcached_io.c

index 77df4319076b8286203cc7d6adfdbb4ea3660c00..8615aa6e13eb38c0433bba15e95fab12a4473ceb 100644 (file)
@@ -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;