Fix for bug in server for touch
authorBrian Aker <brian@tangent.org>
Tue, 12 Feb 2013 09:18:24 +0000 (04:18 -0500)
committerBrian Aker <brian@tangent.org>
Tue, 12 Feb 2013 09:18:24 +0000 (04:18 -0500)
libmemcached/connect.cc
libmemcached/io.cc
libmemcached/response.cc
tests/libmemcached-1.0/touch.cc

index 22e259f41f3335fdfb75dcd23a040bfef4d00cb5..2e2dbf616fbe4fcb22f4fcc437f6fd17e947873b 100644 (file)
@@ -87,7 +87,7 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server, cons
       int local_errno= get_socket_errno(); // We cache in case closesocket() modifies errno
       switch (local_errno)
       {
-#ifdef TARGET_OS_LINUX
+#ifdef __linux__
       case ERESTART:
 #endif
       case EINTR:
@@ -103,22 +103,6 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server, cons
 
       default: // This should not happen
         break;
-#if 0
-        if (fds[0].revents & POLLERR)
-        {
-          int err;
-          socklen_t len= sizeof(err);
-          if (getsockopt(server->fd, SOL_SOCKET, SO_ERROR, (char*)&err, &len) == 0)
-          {
-            if (err == 0)
-            {
-              // This should never happen, if it does? Punt.  
-              continue;
-            }
-            local_errno= err;
-          }
-        }
-#endif
       }
 
       assert_msg(server->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor");
@@ -146,13 +130,9 @@ static memcached_return_t connect_poll(org::libmemcached::Instance* server, cons
         }
       }
 
-      return  memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+      return  memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_literal_param("(number_of == 0)"));
     }
 
-#if 0
-    server->revents(fds[0].revents);
-#endif
-
     assert (number_of == 1);
 
     if (fds[0].revents & POLLERR or
@@ -663,7 +643,8 @@ static memcached_return_t network_connect(org::libmemcached::Instance* server)
 
   if (timeout_error_occured and server->state < MEMCACHED_SERVER_STATE_IN_PROGRESS)
   {
-    return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+    return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT,
+                               memcached_literal_param("if (timeout_error_occured and server->state < MEMCACHED_SERVER_STATE_IN_PROGRESS)"));
   }
 
   return memcached_set_error(*server, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT); /* The last error should be from connect() */
index f6cc36969de7255653517214cf0271e4629b9946..d9a13a7195cf7d6d4e15c1782529a61bce75983e 100644 (file)
@@ -212,7 +212,7 @@ static memcached_return_t io_wait(org::libmemcached::Instance* instance,
 
   if (instance->root->poll_timeout == 0) // Mimic 0 causes timeout behavior (not all platforms do this)
   {
-    return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+    return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_literal_param("poll_timeout() was set to zero"));
   }
 
   size_t loop_max= 5;
@@ -257,7 +257,7 @@ static memcached_return_t io_wait(org::libmemcached::Instance* instance,
 
     if (active_fd == 0)
     {
-      return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+      return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_literal_param("No active_fd were found"));
     }
 
     // Only an error should result in this code being called.
index 85d675bb53bc9bc4bbb859423d8e754c5d2d4712..391c9309814ef10c0eb4d04c0ae0644ed4fd1f94 100644 (file)
@@ -648,6 +648,25 @@ static memcached_return_t binary_read_one_response(org::libmemcached::Instance*
       }
       break;
 
+    case PROTOCOL_BINARY_CMD_TOUCH:
+      {
+        rc= MEMCACHED_SUCCESS;
+        if (bodylen == 4) // The four byte read is a bug?
+        {
+          char touch_buffer[4]; // @todo document this number
+          rc= memcached_safe_read(instance, touch_buffer, sizeof(touch_buffer));
+#if 0
+          fprintf(stderr, "%s:%d %d %d %d %d %.*s(%d)\n", __FILE__, __LINE__,
+                  int(touch_buffer[0]),
+                  int(touch_buffer[1]),
+                  int(touch_buffer[2]),
+                  int(touch_buffer[3]),
+                  int(bodylen), touch_buffer, int(bodylen));
+#endif
+        }
+        return memcached_set_error(*instance, rc, MEMCACHED_AT);
+      }
+
     case PROTOCOL_BINARY_CMD_FLUSH:
     case PROTOCOL_BINARY_CMD_QUIT:
     case PROTOCOL_BINARY_CMD_SET:
@@ -656,14 +675,9 @@ static memcached_return_t binary_read_one_response(org::libmemcached::Instance*
     case PROTOCOL_BINARY_CMD_APPEND:
     case PROTOCOL_BINARY_CMD_PREPEND:
     case PROTOCOL_BINARY_CMD_DELETE:
-    case PROTOCOL_BINARY_CMD_TOUCH:
       {
-        if (bodylen != 0)
-        {
-          char touch_buffer[32]; // @todo document this number
-          rc= memcached_safe_read(instance, buffer, sizeof(touch_buffer));
-        }
-        return memcached_set_error(*instance, rc, MEMCACHED_AT);
+        WATCHPOINT_ASSERT(bodylen == 0);
+        return MEMCACHED_SUCCESS;
       }
 
     case PROTOCOL_BINARY_CMD_NOOP:
index 044273fd4d0a2d5a7c3033bfebdc598d614a27f8..9ce86f00f827353ec196bd91ddb68a75395e4ff1 100644 (file)
@@ -85,14 +85,14 @@ test_return_t test_memcached_touch(memcached_st *memc)
     free(value);
   }
 
-  test_compare(MEMCACHED_SUCCESS,
-               memcached_touch(memc, test_literal_param(__func__), 60 *60));
+  rc= memcached_touch(memc, test_literal_param(__func__), 60 *60);
+  ASSERT_EQ_(MEMCACHED_SUCCESS, rc, "%s", memcached_last_error_message(memc));
 
   rc= memcached_touch(memc, test_literal_param(__func__), 60 *60 *24 *60);
-  test_compare(MEMCACHED_SUCCESS, rc);
+  ASSERT_EQ_(MEMCACHED_SUCCESS, rc, "%s", memcached_last_error_message(memc));
 
-  test_compare(MEMCACHED_NOTFOUND,
-               memcached_exist(memc, test_literal_param(__func__)));
+  rc= memcached_exist(memc, test_literal_param(__func__));
+  ASSERT_EQ_(MEMCACHED_NOTFOUND, rc, "%s", memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
@@ -132,19 +132,20 @@ test_return_t test_memcached_touch_by_key(memcached_st *memc)
     free(value);
   }
 
-  test_compare(MEMCACHED_SUCCESS,
-               memcached_touch_by_key(memc,
-                                      test_literal_param("grouping_key"),
-                                      test_literal_param(__func__),
-                                      60 *60));
+  rc= memcached_touch_by_key(memc,
+                             test_literal_param("grouping_key"),
+                             test_literal_param(__func__),
+                             60 *60);
+  ASSERT_EQ_(MEMCACHED_SUCCESS, rc, "%s", memcached_last_error_message(memc));
 
-  test_compare(MEMCACHED_SUCCESS,
-               memcached_touch_by_key(memc,
-                                      test_literal_param("grouping_key"),
-                                      test_literal_param(__func__),
-                                      60 *60 *24 *60));
-  test_compare(MEMCACHED_NOTFOUND,
-               memcached_exist_by_key(memc, test_literal_param("grouping_key"),test_literal_param(__func__)));
+  rc= memcached_touch_by_key(memc,
+                             test_literal_param("grouping_key"),
+                             test_literal_param(__func__),
+                             60 *60 *24 *60);
+  ASSERT_EQ_(MEMCACHED_SUCCESS, rc, "%s", memcached_last_error_message(memc));
+
+  rc= memcached_exist_by_key(memc, test_literal_param("grouping_key"),test_literal_param(__func__));
+  ASSERT_EQ_(MEMCACHED_NOTFOUND, rc, "%s", memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }