From 1fa5c40c04223a71dd3e617fc134d75a98da4ece Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 12 Feb 2013 04:18:24 -0500 Subject: [PATCH] Fix for bug in server for touch --- libmemcached/connect.cc | 27 ++++--------------------- libmemcached/io.cc | 4 ++-- libmemcached/response.cc | 28 +++++++++++++++++++------- tests/libmemcached-1.0/touch.cc | 35 +++++++++++++++++---------------- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 22e259f4..2e2dbf61 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -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() */ diff --git a/libmemcached/io.cc b/libmemcached/io.cc index f6cc3696..d9a13a71 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -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. diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 85d675bb..391c9309 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -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: diff --git a/tests/libmemcached-1.0/touch.cc b/tests/libmemcached-1.0/touch.cc index 044273fd..9ce86f00 100644 --- a/tests/libmemcached-1.0/touch.cc +++ b/tests/libmemcached-1.0/touch.cc @@ -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; } -- 2.30.2