From 40353ce2b76875202b3d37ad32c645ec18933bed Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sun, 12 Aug 2012 13:34:01 -0400 Subject: [PATCH] Fix snd/recv when number is higher then domain of value. --- libmemcached-1.0/struct/memcached.h | 2 +- libmemcached/connect.cc | 20 ++++++++++++-------- libmemcached/csl/context.h | 3 +++ tests/libmemcached-1.0/mem_functions.cc | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libmemcached-1.0/struct/memcached.h b/libmemcached-1.0/struct/memcached.h index 63b07a00..624887b7 100644 --- a/libmemcached-1.0/struct/memcached.h +++ b/libmemcached-1.0/struct/memcached.h @@ -45,7 +45,7 @@ struct memcached_st { bool is_purging:1; bool is_processing_input:1; bool is_time_for_rebuild:1; - bool not_used:1; + bool is_parsing:1; } state; struct { diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 1ace3fd8..dfe69c0b 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -250,27 +250,26 @@ static void set_socket_options(org::libmemcached::Instance* server) } #ifdef HAVE_SNDTIMEO - if (server->root->snd_timeout) + if (server->root->snd_timeout > 0) { struct timeval waittime; - waittime.tv_sec= 0; - waittime.tv_usec= server->root->snd_timeout; + waittime.tv_sec= server->root->snd_timeout / 1000000; + waittime.tv_usec= server->root->snd_timeout % 1000000; int error= setsockopt(server->fd, SOL_SOCKET, SO_SNDTIMEO, - &waittime, (socklen_t)sizeof(struct timeval)); - (void)(error); + &waittime, (socklen_t)sizeof(struct timeval)); assert(error == 0); } #endif #ifdef HAVE_RCVTIMEO - if (server->root->rcv_timeout) + if (server->root->rcv_timeout > 0) { struct timeval waittime; - waittime.tv_sec= 0; - waittime.tv_usec= server->root->rcv_timeout; + waittime.tv_sec= server->root->rcv_timeout / 1000000; + waittime.tv_usec= server->root->rcv_timeout % 1000000; int error= setsockopt(server->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime, (socklen_t)sizeof(struct timeval)); @@ -737,6 +736,11 @@ static memcached_return_t _memcached_connect(org::libmemcached::Instance* server memcached_return_t memcached_connect_try(org::libmemcached::Instance* server) { + if (server and server->root and server->root->state.is_parsing) + { + return MEMCACHED_SUCCESS; + } + return _memcached_connect(server, false); } diff --git a/libmemcached/csl/context.h b/libmemcached/csl/context.h index 77fac219..12e028dd 100644 --- a/libmemcached/csl/context.h +++ b/libmemcached/csl/context.h @@ -61,6 +61,8 @@ public: memc= memc_arg; init_scanner(); rc= MEMCACHED_SUCCESS; + + memc->state.is_parsing= true; } bool end() @@ -106,6 +108,7 @@ public: ~Context() { destroy_scanner(); + memc->state.is_parsing= false; } yytokentype previous_token; diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 07603cb4..3b1701e8 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -4480,6 +4480,7 @@ test_return_t regression_1021819_TEST(memcached_st *original) test_true(memc); test_compare(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 2000000), MEMCACHED_SUCCESS); + test_compare(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 3000000), MEMCACHED_SUCCESS); memcached_return_t rc; -- 2.30.2