Big change, we use poll() now instead of select()
authorBrian Aker <brian@tangent.org>
Fri, 19 Oct 2007 22:18:10 +0000 (15:18 -0700)
committerBrian Aker <brian@tangent.org>
Fri, 19 Oct 2007 22:18:10 +0000 (15:18 -0700)
1) It is faster.
2) I think this means bye bye to the random write failure.

Difference?

select():
Testing user_supplied_bug1                                       3.512 [ ok ]
Testing user_supplied_bug2                                       3.461 [ ok ]

poll():
Testing user_supplied_bug1                                       1.324 [ ok ]
Testing user_supplied_bug2                                       1.303 [ ok ]

This commit also update variables for next release.

ChangeLog
configure.in
lib/memcached_io.c
support/libmemcached.spec

index be55ed746c1d62916bb7f375679d83a34f067407..ed287957dffdf415bd27d251246ff9a3c9bdc36e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.7
+  * Poved to poll() from select()
+
 0.6 Wed Oct 17 08:41:35 PDT 2007
   * get value returns are now null terminated (request by Cal Heldenbrand) 
   * Fixed connections for more hosts then two.
index 79c91a7418fbcb6bd0b5cb48e35e9e98d1a66799..b6b849d4d3c29ebf7dd0de483970200f3e7a373f 100644 (file)
@@ -1,7 +1,7 @@
 AC_INIT(src/memcat.c)
 AC_CONFIG_AUX_DIR(config)
 AM_CONFIG_HEADER(include/libmemcached_config.h)
-AM_INIT_AUTOMAKE("libmemcached", 0.6)
+AM_INIT_AUTOMAKE("libmemcached", 0.7)
 
 AC_PROG_CC
 AC_PROG_LIBTOOL
index 54a4b8dcd16d6c154604349533c03c9a067942e0..45a12199e5241d40e749ec0a8f0b6b2fe4139fed 100644 (file)
@@ -5,6 +5,58 @@
 #include "common.h"
 #include "memcached_io.h"
 #include <sys/select.h>
+#include <poll.h>
+
+int io_wait(memcached_st *ptr, unsigned int server_key, unsigned read_or_write)
+{
+  struct pollfd fds[1];
+  short flags= 0;
+
+  if (read_or_write)
+    flags= POLLOUT |  POLLERR;
+  else
+    flags= POLLIN | POLLERR;
+
+  memset(&fds, 0, sizeof(struct pollfd));
+  fds[0].fd= ptr->hosts[server_key].fd;
+  fds[0].events= flags;
+
+  if (poll(fds, 1, -1) < 0)
+    return MEMCACHED_FAILURE;
+
+  return MEMCACHED_SUCCESS;
+#ifdef OLD
+  while (1)
+  {
+    int select_return;
+    struct timeval local_tv;
+    fd_set set;
+
+    memset(&local_tv, 0, sizeof(struct timeval));
+
+    local_tv.tv_sec= 0;
+    local_tv.tv_usec= 300;
+
+    FD_ZERO(&set);
+    FD_SET(ptr->hosts[server_key].fd, &set);
+
+    if (read_or_write)
+      select_return= select(1, &set, NULL, NULL, &local_tv);
+    else
+      select_return= select(1, NULL, &set, NULL, &local_tv);
+
+    if (select_return == -1)
+    {
+      ptr->my_errno= errno;
+      return MEMCACHED_FAILURE;
+    }
+    else if (!select_return)
+      break;
+  }
+
+  return MEMCACHED_SUCCESS;
+#endif
+}
 
 ssize_t memcached_io_read(memcached_st *ptr, unsigned  int server_key,
                           char *buffer, size_t length)
@@ -23,30 +75,11 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned  int server_key,
       {
         if (ptr->flags & MEM_NO_BLOCK)
         {
-          while (1)
-          {
-            int select_return;
-            struct timeval local_tv;
-            fd_set set;
+          memcached_return rc;
 
-            memset(&local_tv, 0, sizeof(struct timeval));
-
-            local_tv.tv_sec= 0;
-            local_tv.tv_usec= 300;
-
-            FD_ZERO(&set);
-            FD_SET(ptr->hosts[server_key].fd, &set);
-
-            select_return= select(1, &set, NULL, NULL, &local_tv);
-
-            if (select_return == -1)
-            {
-              ptr->my_errno= errno;
-              return -1;
-            }
-            else if (!select_return)
-              break;
-          }
+          rc= io_wait(ptr, server_key, 0);
+          if (rc != MEMCACHED_SUCCESS)
+            return -1;
         }
 
         data_read= recv(ptr->hosts[server_key].fd, 
@@ -128,29 +161,11 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key)
   {
     if (ptr->flags & MEM_NO_BLOCK)
     {
+      memcached_return rc;
 
-      while (1)
-      {
-        struct timeval local_tv;
-        fd_set set;
-        int select_return;
-
-        local_tv.tv_sec= 0;
-        local_tv.tv_usec= 300 * loop;
-
-        FD_ZERO(&set);
-        FD_SET(ptr->hosts[server_key].fd, &set);
-
-        select_return= select(1, NULL, &set, NULL, &local_tv);
-
-        if (select_return == -1)
-        {
-          ptr->my_errno= errno;
-          return -1;
-        }
-        else if (!select_return)
-          break;
-      }
+      rc= io_wait(ptr, server_key, 1);
+      if (rc != MEMCACHED_SUCCESS)
+        return -1;
     }
 
     sent_length= 0;
index 67ccbb63caf6a2239795dc81b01b1022584f3dcf..f5880308661a50694643af65e9a0cdf4a9116b26 100644 (file)
@@ -1,6 +1,6 @@
 Summary: memcached C library and command line tools
 Name: libmemcached
-Version: 0.6
+Version: 0.7
 Release: 1
 License: BSD
 Group: System Environment/Libraries