Updating server_st to keep client buffers per server.
authorBrian Aker <brian@tangent.org>
Fri, 9 Nov 2007 22:18:25 +0000 (14:18 -0800)
committerBrian Aker <brian@tangent.org>
Fri, 9 Nov 2007 22:18:25 +0000 (14:18 -0800)
This is ground work to allow more async efforts around protocol.

ChangeLog
include/memcached.h
lib/memcached_hosts.c
lib/memcached_io.c

index 170f73782715934451dbb6cbc7b5bac364624443..1a54023afa169cbf3667a2e64bf11e437d9e6a8f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+0.9
+  * fix for when no servers are definied.
+  * different buffers are now kept for different connections to
+    speed up async efforts
+
 0.8 Mon Nov  5 10:40:41 PST 2007
   * Adding support for CRC hash method 
   * Adding support for UNIX sockets
index 51c5e94eda8158793cb7ab8bd7ad1159828787e2..a684a1ecd24186e2a041f9b1dc43b1a204f0c8c3 100644 (file)
@@ -101,6 +101,11 @@ struct memcached_server_st {
   int fd;
   unsigned int stack_responses;
   unsigned int cursor_active;
+  char write_buffer[MEMCACHED_MAX_BUFFER];
+  size_t write_buffer_offset;
+  char read_buffer[MEMCACHED_MAX_BUFFER];
+  size_t read_buffer_length;
+  char *read_ptr;
   memcached_connection type;
 };
 
@@ -157,11 +162,6 @@ struct memcached_st {
   memcached_server_st *hosts;
   unsigned int number_of_hosts;
   unsigned int cursor_server;
-  char read_buffer[MEMCACHED_MAX_BUFFER];
-  size_t read_buffer_length;
-  char *read_ptr;
-  char write_buffer[MEMCACHED_MAX_BUFFER];
-  size_t write_buffer_offset;
   char connected;
   int cached_errno;
   unsigned long long flags;
index ad0cad2e438d9d20d9cfd675c1dbc94e9300a0ae..c77e5583eb2d9caa7146dee6a998a6cc9f47768f 100644 (file)
@@ -15,6 +15,9 @@ static void host_reset(memcached_server_st *host, char *new_hostname, unsigned i
   host->port= port;
   host->fd= -1;
   host->type= type;
+  host->write_buffer_offset= 0;
+  host->read_buffer_length= 0;
+  host->read_ptr= host->read_buffer;
 }
 
 memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *list)
index 54844be445956547705d779bc1eb30934a4b0f1d..473b8881dc2bd61f1d6703d948ff35887da307e2 100644 (file)
@@ -36,7 +36,7 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned  int server_key,
 
   while (length)
   {
-    if (!ptr->read_buffer_length)
+    if (!ptr->hosts[server_key].read_buffer_length)
     {
       size_t data_read;
 
@@ -52,7 +52,7 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned  int server_key,
         }
 
         data_read= read(ptr->hosts[server_key].fd, 
-                        ptr->read_buffer, 
+                        ptr->hosts[server_key].read_buffer, 
                         MEMCACHED_MAX_BUFFER);
         if (data_read == -1)
         {
@@ -72,14 +72,14 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned  int server_key,
         /* If zero, just keep looping */
       }
 
-      ptr->read_buffer_length= data_read;
-      ptr->read_ptr= ptr->read_buffer;
+      ptr->hosts[server_key].read_buffer_length= data_read;
+      ptr->hosts[server_key].read_ptr= ptr->hosts[server_key].read_buffer;
     }
 
-    *buffer_ptr= *ptr->read_ptr;
+    *buffer_ptr= *ptr->hosts[server_key].read_ptr;
     length--;
-    ptr->read_ptr++;
-    ptr->read_buffer_length--;
+    ptr->hosts[server_key].read_ptr++;
+    ptr->hosts[server_key].read_buffer_length--;
     buffer_ptr++;
   }
 
@@ -93,17 +93,17 @@ ssize_t memcached_io_write(memcached_st *ptr, unsigned int server_key,
 
   for (x= 0; x < length; x++)
   {
-    ptr->write_buffer[ptr->write_buffer_offset]= buffer[x];
-    ptr->write_buffer_offset++;
+    ptr->hosts[server_key].write_buffer[ptr->hosts[server_key].write_buffer_offset]= buffer[x];
+    ptr->hosts[server_key].write_buffer_offset++;
 
-    if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER)
+    if (ptr->hosts[server_key].write_buffer_offset == MEMCACHED_MAX_BUFFER)
     {
       size_t sent_length;
 
       sent_length= memcached_io_flush(ptr, server_key);
 
       WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER);
-      ptr->write_buffer_offset= 0;
+      ptr->hosts[server_key].write_buffer_offset= 0;
     }
   }
 
@@ -120,11 +120,11 @@ 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;
+  char *write_ptr= ptr->hosts[server_key].write_buffer;
+  size_t write_length= ptr->hosts[server_key].write_buffer_offset;
   unsigned int loop= 1;
 
-  if (ptr->write_buffer_offset == 0)
+  if (ptr->hosts[server_key].write_buffer_offset == 0)
     return 0;
 
   return_length= 0;
@@ -167,8 +167,8 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key)
   }
 
   WATCHPOINT_ASSERT(write_length == 0);
-  WATCHPOINT_ASSERT(return_length == ptr->write_buffer_offset);
-  ptr->write_buffer_offset= 0;
+  WATCHPOINT_ASSERT(return_length == ptr->hosts[server_key].write_buffer_offset);
+  ptr->hosts[server_key].write_buffer_offset= 0;
 
   return return_length;
 }
@@ -178,6 +178,6 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key)
 */
 void memcached_io_reset(memcached_st *ptr, unsigned int server_key)
 {
-  ptr->write_buffer_offset= 0;
+  ptr->hosts[server_key].write_buffer_offset= 0;
   memcached_quit(ptr);
 }