Merge fix.
author <brian@gir-2.local> <>
Tue, 19 Feb 2008 06:10:47 +0000 (11:40 +0530)
committer <brian@gir-2.local> <>
Tue, 19 Feb 2008 06:10:47 +0000 (11:40 +0530)
ChangeLog
configure.ac
docs/memcached_behavior.pod
include/memcached.h
lib/memcached_behavior.c
lib/memcached_connect.c

index daa339b9cbcf43e3943ab2c7d2da13280957c69c..46c15ea9e2555a034274f50362419b7e872e431c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+0.17
+  * MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT added for connect timeout in
+    non-block mode.
+
 0.16 Mon Feb 18 00:30:25 PST 2008
   * Work on the UDP protocol
   * Added get_by_key, set_by_key tests for C++ API
index d1a1da75fe7dadfe6beff89fd0a7eb9d6c368901..b70514adce3ecf21e209a970a307932b5ee84b18 100644 (file)
@@ -7,7 +7,7 @@ MEMCACHED_LIBRARY_NAME=libmemcached
 
 #release versioning
 MEMCACHED_MAJOR_VERSION=0
-MEMCACHED_MINOR_VERSION=16
+MEMCACHED_MINOR_VERSION=17
 MEMCACHED_MICRO_VERSION=0
 
 #API version
index 50e215f874ca996356f4be4d86bb2ec0a58a9e76..74a3a732396a21fe70c90d05587c74ac5c1ee68d 100755 (executable)
@@ -98,6 +98,11 @@ are valid keys.
 Enabling this will cause hosts that are added to be placed in the host list in 
 sorted order. This will defeat consisten hashing.
 
+=item MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT
+
+In non-blocking mode this changes the value of the timeout during socket
+connection.
+
 =back
 
 =head1 RETURN
index 759a69590496ed179eae5bccff3449e54d603f04..5458974170e997ffaf1a78899c44de4970baf3f7 100644 (file)
@@ -32,7 +32,7 @@ extern "C" {
 #define MEMCACHED_DEFAULT_TIMEOUT INT32_MAX
 
 /* string value */
-#define LIBMEMCACHED_VERSION_STRING "0.16"
+#define LIBMEMCACHED_VERSION_STRING "0.17"
 
 typedef enum {
   MEMCACHED_SUCCESS,
@@ -102,6 +102,7 @@ typedef enum {
   MEMCACHED_BEHAVIOR_USER_DATA,
   MEMCACHED_BEHAVIOR_SORT_HOSTS,
   MEMCACHED_BEHAVIOR_VERIFY_KEY,
+  MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT,
 } memcached_behavior;
 
 typedef enum {
@@ -217,6 +218,7 @@ struct memcached_st {
   int send_size;
   int recv_size;
   int32_t poll_timeout;
+  int32_t connect_timeout;
   memcached_result_st result;
   memcached_hash hash;
   memcached_server_distribution distribution;
index 8c02a383d7e6b9abe313983d61f643cfcc3a4425..15ee08c9eaaf5a49749624eb13ab5dbdc467e18d 100644 (file)
@@ -73,6 +73,13 @@ memcached_return memcached_behavior_set(memcached_st *ptr,
       ptr->poll_timeout= timeout;
       break;
     }
+  case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
+    {
+      int32_t timeout= (*((int32_t *)data));
+
+      ptr->connect_timeout= timeout;
+      break;
+    }
   case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
     {
       ptr->send_size= (*((int *)data));
@@ -133,6 +140,10 @@ unsigned long long memcached_behavior_get(memcached_st *ptr,
     {
       return (unsigned long long)ptr->poll_timeout;
     }
+  case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
+    {
+      return (unsigned long long)ptr->connect_timeout;
+    }
   case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
     {
       int sock_size;
index b4642c7630fb542ece0935e0f9312ebf31b7ab60..50c6fa62acacd3e40823909343586735cce5d093 100644 (file)
@@ -135,9 +135,49 @@ test_connect:
                 sizeof(servAddr)) < 0)
     {
       switch (errno) {
+      case EINPROGRESS:
+        {
+        struct timeval tm = { ptr->root->connect_timeout, 0 };
+        socklen_t len= sizeof(int);
+        fd_set wset;
+        int error=0, value;
+
+        FD_ZERO(&wset);
+        FD_SET(ptr->fd, &wset);
+
+        select(ptr->fd+1, NULL, &wset, NULL, &tm);
+        if (FD_ISSET(ptr->fd, &wset) != 0)
+        {
+          if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &value, &len) == 0)
+          {
+            if (value)
+            {
+              error= 1;
+            }
+          }
+          else
+          {
+            error= 1;
+          }
+        }
+        else
+        {
+          error= 1;
+        }
+
+        if (error)
+        {
+          ptr->cached_errno= errno;
+          WATCHPOINT_ERRNO(ptr->cached_errno);
+          close(ptr->fd);
+          ptr->fd= -1;
+          return MEMCACHED_ERRNO;
+        }
+
+        break;
+        }
         /* We are spinning waiting on connect */
       case EALREADY:
-      case EINPROGRESS:
       case EINTR:
         goto test_connect;
       case EISCONN: /* We were spinning waiting on connect */