From: Brian Aker Date: Mon, 5 Apr 2010 19:01:19 +0000 (-0700) Subject: Merge Andre X-Git-Tag: 0.40~16 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=26c65ac524f21cd73a79f3caf45cdb76c9a41bc0;p=m6w6%2Flibmemcached Merge Andre --- 26c65ac524f21cd73a79f3caf45cdb76c9a41bc0 diff --cc libmemcached/memcached.h index 81120c54,1392cb2b..2244c62d --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@@ -65,22 -64,23 +65,23 @@@ struct memcached_st } state; struct { // Everything below here is pretty static. - bool auto_eject_hosts MEMCACHED_BITFIELD; - bool binary_protocol MEMCACHED_BITFIELD; - bool buffer_requests MEMCACHED_BITFIELD; - bool cork MEMCACHED_BITFIELD; - bool hash_with_prefix_key MEMCACHED_BITFIELD; - bool ketama_weighted MEMCACHED_BITFIELD; - bool no_block MEMCACHED_BITFIELD; - bool no_reply MEMCACHED_BITFIELD; - bool randomize_replica_read MEMCACHED_BITFIELD; - bool reuse_memory MEMCACHED_BITFIELD; - bool support_cas MEMCACHED_BITFIELD; - bool tcp_nodelay MEMCACHED_BITFIELD; - bool use_cache_lookups MEMCACHED_BITFIELD; - bool use_sort_hosts MEMCACHED_BITFIELD; - bool use_udp MEMCACHED_BITFIELD; - bool verify_key MEMCACHED_BITFIELD; - bool tcp_keepalive MEMCACHED_BITFIELD; + bool auto_eject_hosts:1; + bool binary_protocol:1; + bool buffer_requests:1; + bool cork:1; + bool hash_with_prefix_key:1; + bool ketama_weighted:1; + bool no_block:1; + bool no_reply:1; + bool randomize_replica_read:1; + bool reuse_memory:1; + bool support_cas:1; + bool tcp_nodelay:1; + bool use_cache_lookups:1; + bool use_sort_hosts:1; + bool use_udp:1; + bool verify_key:1; ++ bool tcp_keepalive:1; } flags; memcached_server_distribution_t distribution; hashkit_st hashkit; diff --cc libmemcached/storage.c index 2b232fe7,ba66cf87..be0040a4 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@@ -145,48 -145,52 +145,47 @@@ static inline memcached_return_t memcac if (write_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) { rc= MEMCACHED_WRITE_FAILURE; -- goto error; -- } -- - /* Send command header */ - rc= memcached_do(instance, buffer, write_length, false); - if (rc != MEMCACHED_SUCCESS) - goto error; -- - struct __write_vector_st vector[]= - /* Send command body */ - if (memcached_io_write(instance, value, value_length, false) == -1) -- { - { .length= write_length, .buffer= buffer }, - { .length= value_length, .buffer= value }, - { .length= 2, .buffer= "\r\n" } - }; - rc= MEMCACHED_WRITE_FAILURE; - goto error; - } -- -- if (ptr->flags.buffer_requests && verb == SET_OP) -- { -- to_write= false; } else { -- to_write= true; -- } - - /* Send command header */ - rc= memcached_vdo(instance, vector, 3, to_write); - if (rc == MEMCACHED_SUCCESS) - { - - if (ptr->flags.no_reply) - return (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; - - if (to_write == false) - return MEMCACHED_BUFFERED; - - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); - - if (rc == MEMCACHED_STORED) - return MEMCACHED_SUCCESS; - else - return rc; ++ struct __write_vector_st vector[]= ++ { ++ { .length= write_length, .buffer= buffer }, ++ { .length= value_length, .buffer= value }, ++ { .length= 2, .buffer= "\r\n" } ++ }; + - if (memcached_io_write(instance, "\r\n", 2, to_write) == -1) - { - rc= MEMCACHED_WRITE_FAILURE; - goto error; - } ++ if (ptr->flags.buffer_requests && verb == SET_OP) ++ { ++ to_write= false; ++ } ++ else ++ { ++ to_write= true; ++ } + - if (ptr->flags.no_reply) - return (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; ++ /* Send command header */ ++ rc= memcached_vdo(instance, vector, 3, to_write); ++ if (rc == MEMCACHED_SUCCESS) ++ { + - if (to_write == false) - return MEMCACHED_BUFFERED; ++ if (ptr->flags.no_reply) ++ return (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; + - rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); ++ if (to_write == false) ++ return MEMCACHED_BUFFERED; + - if (rc == MEMCACHED_STORED) - return MEMCACHED_SUCCESS; - else - return rc; ++ rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); ++ ++ if (rc == MEMCACHED_STORED) ++ return MEMCACHED_SUCCESS; ++ else ++ return rc; ++ } + } --error: - - memcached_io_reset(instance); + if (rc == MEMCACHED_WRITE_FAILURE) + memcached_io_reset(instance); return rc; } diff --cc tests/mem_functions.c index dca68b12,84ac0dc1..75d00932 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@@ -1939,6 -1933,6 +1939,54 @@@ static test_return_t MEMCACHED_BEHAVIOR return TEST_SUCCESS; } ++ ++static test_return_t MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test(memcached_st *memc) ++{ ++ memcached_return_t rc; ++ bool set= true; ++ bool value; ++ ++ rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, set); ++ test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOT_SUPPORTED); ++ ++ value= (bool)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE); ++ ++ if (rc == MEMCACHED_SUCCESS) ++ { ++ test_true((bool)value == set); ++ } ++ else ++ { ++ test_false((bool)value == set); ++ } ++ ++ return TEST_SUCCESS; ++} ++ ++ ++static test_return_t MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test(memcached_st *memc) ++{ ++ memcached_return_t rc; ++ bool set= true; ++ bool value; ++ ++ rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, set); ++ test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOT_SUPPORTED); ++ ++ value= (bool)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE); ++ ++ if (rc == MEMCACHED_SUCCESS) ++ { ++ test_true((bool)value == set); ++ } ++ else ++ { ++ test_false((bool)value == set); ++ } ++ ++ return TEST_SUCCESS; ++} ++ static test_return_t fetch_all_results(memcached_st *memc) { memcached_return_t rc= MEMCACHED_SUCCESS; @@@ -5646,6 -5566,6 +5694,8 @@@ test_st tests[] = test_st behavior_tests[] ={ {"behavior_test", 0, (test_callback_fn)behavior_test}, {"MEMCACHED_BEHAVIOR_CORK", 0, (test_callback_fn)MEMCACHED_BEHAVIOR_CORK_test}, ++ {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", 0, (test_callback_fn)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test}, ++ {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", 0, (test_callback_fn)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test}, {0, 0, 0} };