From: Brian Aker Date: Thu, 10 May 2012 06:30:56 +0000 (-0700) Subject: Update memcached, fix style in test cases. X-Git-Tag: 1.0.8~6^2~2^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e50ced7764a1ddb80aba8f7c8851c4181a2cfc4e;p=m6w6%2Flibmemcached Update memcached, fix style in test cases. --- diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 8ffbd665..68e617d1 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -287,7 +287,7 @@ bool _is_auto_eject_host(const memcached_st *ptr) uint64_t memcached_behavior_get(memcached_st *ptr, const memcached_behavior_t flag) { - if (not ptr) + if (ptr == NULL) { return MEMCACHED_INVALID_ARGUMENTS; } diff --git a/libmemcached/io.cc b/libmemcached/io.cc index e83522b9..8fb6ffda 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -551,15 +551,17 @@ memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr) return MEMCACHED_CONNECTION_FAILURE; } -static ssize_t _io_write(memcached_server_write_instance_st ptr, - const void *buffer, size_t length, bool with_flush) +static bool _io_write(memcached_server_write_instance_st ptr, + const void *buffer, size_t length, bool with_flush, + size_t& written) { WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); assert(memcached_is_udp(ptr->root) == false); - size_t original_length= length; const char *buffer_ptr= static_cast(buffer); + const size_t original_length= length; + while (length) { char *write_ptr; @@ -580,7 +582,8 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, memcached_return_t rc; if (io_flush(ptr, with_flush, rc) == false) { - return -1; + written= original_length -length; + return false; } } } @@ -591,22 +594,33 @@ static ssize_t _io_write(memcached_server_write_instance_st ptr, WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); if (io_flush(ptr, with_flush, rc) == false) { - return -1; + written= original_length -length; + return false; } } - return ssize_t(original_length); + written= original_length -length; + + return true; } bool memcached_io_write(memcached_server_write_instance_st ptr) { - return (_io_write(ptr, NULL, 0, true) >= 0); + size_t written; + return _io_write(ptr, NULL, 0, true, written); } ssize_t memcached_io_write(memcached_server_write_instance_st ptr, const void *buffer, const size_t length, const bool with_flush) { - return _io_write(ptr, buffer, length, with_flush); + size_t written; + + if (_io_write(ptr, buffer, length, with_flush, written) == false) + { + return -1; + } + + return ssize_t(written); } ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, @@ -617,15 +631,14 @@ ssize_t memcached_io_writev(memcached_server_write_instance_st ptr, for (size_t x= 0; x < number_of; x++, vector++) { - ssize_t returnable; - if (vector->length) { - if ((returnable= _io_write(ptr, vector->buffer, vector->length, false)) == -1) + size_t written; + if ((_io_write(ptr, vector->buffer, vector->length, false, written)) == false) { return -1; } - total+= returnable; + total+= written; } } diff --git a/memcached/.gitignore b/memcached/.gitignore new file mode 100644 index 00000000..1dbb0413 --- /dev/null +++ b/memcached/.gitignore @@ -0,0 +1,41 @@ +*.[ao] +*.gcov +*.gcda +*.gcno +*.tcov +.deps +INSTALL +Makefile +Makefile.in +config.guess +config.h +config.h.in +config.log +config.status +config.sub +aclocal.m4 +compile +autom4te.cache +configure +depcomp +install-sh +memcached +memcached-debug +memcached-debug.profile +missing +stamp-h1 +tags +TAGS +cscope.out +memcached_dtrace.h +*~ +memcached-*.tar.gz +doc/protocol-binary-range.txt +doc/protocol-binary.txt +/sizes +/version.m4 +/version.num +/testapp +/timedrun +/doc/doxy +/memcached.spec diff --git a/memcached/hash.c b/memcached/hash.c index 6c9b9b6a..f7d21dd3 100644 --- a/memcached/hash.c +++ b/memcached/hash.c @@ -178,8 +178,6 @@ uint32_t hash( case 2 : a+=k[0]&0xffff; break; case 1 : a+=k[0]&0xff; break; case 0 : return c; /* zero length strings require no mixing */ - default: - abort(); } #else /* make valgrind happy */ @@ -249,8 +247,6 @@ uint32_t hash( case 1 : a+=k8[0]; break; case 0 : return c; /* zero length strings require no mixing */ - default: - abort(); } } else { /* need to read the key one byte at a time */ @@ -293,8 +289,6 @@ uint32_t hash( case 1 : a+=k[0]; break; case 0 : return c; /* zero length strings require no mixing */ - default: - abort(); } } diff --git a/memcached/memcached.c b/memcached/memcached.c index 10374421..d4b48121 100644 --- a/memcached/memcached.c +++ b/memcached/memcached.c @@ -1000,10 +1000,6 @@ static void write_bin_error(conn *c, protocol_binary_response_status err, int sw case PROTOCOL_BINARY_RESPONSE_AUTH_ERROR: errstr = "Auth failure."; break; - case PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE: - assert(false); - case PROTOCOL_BINARY_RESPONSE_SUCCESS: - assert(false); default: assert(false); errstr = "UNHANDLED ERROR"; @@ -1133,10 +1129,6 @@ static void complete_incr_bin(conn *c) { case DELTA_ITEM_CAS_MISMATCH: write_bin_error(c, PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS, 0); break; - - default: - assert(0); - abort(); } } @@ -1204,9 +1196,6 @@ static void complete_update_bin(conn *c) { eno = PROTOCOL_BINARY_RESPONSE_NOT_STORED; } write_bin_error(c, eno, 0); - default: - assert(false); - abort(); } item_remove(c->item); /* release the c->item reference */ @@ -2246,10 +2235,6 @@ static void complete_nread_binary(conn *c) { case bin_reading_sasl_auth_data: process_bin_complete_sasl_auth(c); break; - case bin_reading_cas_header: - assert(0); - case bin_no_state: - assert(0); default: fprintf(stderr, "Not handling substate %d\n", c->substate); assert(0); @@ -3072,9 +3057,6 @@ static void process_arithmetic_command(conn *c, token_t *tokens, const size_t nt break; case DELTA_ITEM_CAS_MISMATCH: break; /* Should never get here */ - default: - assert(false); - abort(); } } @@ -3409,9 +3391,6 @@ static void process_command(conn *c, char *command) { case REASSIGN_SRC_DST_SAME: out_string(c, "SAME src and dst class are identical"); break; - default: - assert(false); - abort(); } return; } else if (ntokens == 4 && @@ -3866,9 +3845,6 @@ static void drive_machine(conn *c) { case READ_MEMORY_ERROR: /* Failed to allocate more memory */ /* State already set by try_read_network */ break; - default: - assert(false); - abort(); } break; @@ -4078,9 +4054,6 @@ static void drive_machine(conn *c) { case TRANSMIT_SOFT_ERROR: stop = true; break; - default: - assert(false); - abort(); } break; @@ -4095,9 +4068,6 @@ static void drive_machine(conn *c) { case conn_max_state: assert(false); break; - default: - assert(false); - abort(); } } diff --git a/memcached/slabs.c b/memcached/slabs.c index 7cffe434..5af0b5ae 100644 --- a/memcached/slabs.c +++ b/memcached/slabs.c @@ -597,9 +597,6 @@ static int slab_rebalance_move(void) { break; case MOVE_PASS: break; - default: - assert(false); - abort(); } slab_rebal.slab_pos = (char *)slab_rebal.slab_pos + s_cls->size; diff --git a/tests/libmemcached-1.0/replication.cc b/tests/libmemcached-1.0/replication.cc index da3f82b3..502bd541 100644 --- a/tests/libmemcached-1.0/replication.cc +++ b/tests/libmemcached-1.0/replication.cc @@ -50,7 +50,8 @@ using namespace libtest; test_return_t check_replication_sanity_TEST(memcached_st *memc) { test_true(memc); - test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); + test_compare(uint64_t(1), + memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); /* * Make sure that we store the item on all servers @@ -63,9 +64,10 @@ test_return_t check_replication_sanity_TEST(memcached_st *memc) test_return_t replication_set_test(memcached_st *memc) { - memcached_return_t rc; memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); + test_true(memc_clone); + test_compare(MEMCACHED_SUCCESS, + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0)); test_compare(MEMCACHED_SUCCESS, memcached_set(memc, "bubba", 5, "0", 1, 0, 0)); @@ -96,6 +98,7 @@ test_return_t replication_set_test(memcached_st *memc) const char key[2]= { (char)x, 0 }; size_t len; uint32_t flags; + memcached_return_t rc; char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, &len, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); @@ -110,7 +113,6 @@ test_return_t replication_set_test(memcached_st *memc) test_return_t replication_get_test(memcached_st *memc) { - memcached_return_t rc; /* * Don't do the following in your code. I am abusing the internal details @@ -130,6 +132,7 @@ test_return_t replication_get_test(memcached_st *memc) const char key[2]= { (char)x, 0 }; size_t len; uint32_t flags; + memcached_return_t rc; char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5, &len, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); @@ -145,17 +148,17 @@ test_return_t replication_get_test(memcached_st *memc) test_return_t replication_mget_test(memcached_st *memc) { - memcached_return_t rc; memcached_st *memc_clone= memcached_clone(NULL, memc); - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0); + test_true(memc_clone); + test_compare(MEMCACHED_SUCCESS, + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0)); const char *keys[]= { "bubba", "key1", "key2", "key3" }; size_t len[]= { 5, 4, 4, 4 }; for (size_t x= 0; x< 4; ++x) { - rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[x], len[x], "0", 1, 0, 0)); } /* @@ -190,13 +193,14 @@ test_return_t replication_mget_test(memcached_st *memc) { char key[2]= { (char)x, 0 }; - rc= memcached_mget_by_key(new_clone, key, 1, keys, len, 4); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(MEMCACHED_SUCCESS, + memcached_mget_by_key(new_clone, key, 1, keys, len, 4)); memcached_result_st *results= memcached_result_create(new_clone, &result_obj); test_true(results); int hits= 0; + memcached_return_t rc; while ((results= memcached_fetch_result(new_clone, &result_obj, &rc)) != NULL) { hits++; @@ -216,7 +220,6 @@ test_return_t replication_mget_test(memcached_st *memc) test_return_t replication_randomize_mget_test(memcached_st *memc) { memcached_result_st result_obj; - memcached_return_t rc; memcached_st *memc_clone= memcached_clone(NULL, memc); memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 3); memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1); @@ -226,8 +229,8 @@ test_return_t replication_randomize_mget_test(memcached_st *memc) for (size_t x= 0; x< 7; ++x) { - rc= memcached_set(memc, keys[x], len[x], "1", 1, 0, 0); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, keys[x], len[x], "1", 1, 0, 0)); } memcached_quit(memc); @@ -243,6 +246,7 @@ test_return_t replication_randomize_mget_test(memcached_st *memc) test_true(results); int hits= 0; + memcached_return_t rc; while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL) { ++hits; @@ -251,6 +255,7 @@ test_return_t replication_randomize_mget_test(memcached_st *memc) memcached_result_free(&result_obj); } memcached_free(memc_clone); + return TEST_SUCCESS; } @@ -261,7 +266,7 @@ test_return_t replication_delete_test(memcached_st *memc_just_cloned) memcached_st *memc_replicated= memcached_clone(NULL, memc_just_cloned); const char *keys[]= { "bubba", "key1", "key2", "key3", "key4" }; - test_true(memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); + test_compare(uint64_t(1), memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_replicated, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, false)); // Make one copy @@ -331,11 +336,11 @@ test_return_t replication_randomize_mget_fail_test(memcached_st *memc) for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x) { const char *key= memcached_strerror(NULL, memcached_return_t(x)); - memcached_return_t rc; uint32_t flags; size_t value_length; + memcached_return_t rc; char *value= memcached_get(memc_clone, key, strlen(key), &value_length, &flags, &rc); - test_true(rc == MEMCACHED_SUCCESS); + test_compare(MEMCACHED_SUCCESS, rc); test_compare(strlen(key), value_length); test_strcmp(key, value); free(value);