#include <ctime>
#include <sys/types.h>
+static bool __is_ketama(memcached_st *ptr)
+{
+ switch (ptr->distribution)
+ {
+ case MEMCACHED_DISTRIBUTION_CONSISTENT:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED:
+ return true;
+
+ case MEMCACHED_DISTRIBUTION_MODULA:
+ case MEMCACHED_DISTRIBUTION_RANDOM:
+ case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
+ break;
+ }
+
+ return false;
+}
+
/*
This function is used to modify the behavior of running client.
return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- return ptr->ketama.weighted;
+ if (__is_ketama(ptr))
+ {
+ return ptr->ketama.weighted;
+ }
+ return false;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
- return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0;
+ return __is_ketama(ptr);
case MEMCACHED_BEHAVIOR_HASH:
return hashkit_get_function(&ptr->hashkit);
return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("Invalid memcached_server_distribution_t"));
}
+ ptr->distribution= type;
return run_distribution(ptr);
}
return io_wait(ptr, MEM_WRITE);
}
-static memcached_return_t _io_fill(memcached_server_write_instance_st ptr, ssize_t& nread)
+static memcached_return_t _io_fill(memcached_server_write_instance_st ptr)
{
ssize_t data_read;
do
case EFAULT:
case ECONNREFUSED:
default:
- {
- memcached_quit_server(ptr, true);
- nread= -1;
- return memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
- }
+ memcached_quit_server(ptr, true);
+ memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT);
+ break;
}
+
+ return memcached_server_error_return(ptr);
}
else if (data_read == 0)
{
it will return EGAIN if data is not immediatly available.
*/
memcached_quit_server(ptr, true);
- nread= -1;
return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT,
memcached_literal_param("::rec() returned zero, server has disconnected"));
}
if (ptr->read_buffer_length == 0)
{
memcached_return_t io_fill_ret;
- if (memcached_fatal(io_fill_ret= _io_fill(ptr, nread)))
+ if (memcached_fatal(io_fill_ret= _io_fill(ptr)))
{
+ nread= -1;
return io_fill_ret;
}
}
{ } // It is possible that the value has been purged.
else
{
- test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc));
+ test_compare(MEMCACHED_SUCCESS, rc);
}
test_null(out_value);
test_zero(value_length);
keys.key_at(x), keys.length_at(x),
blob, sizeof(blob),
0, 0);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED,
- memcached_last_error_message(memc));
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
test_compare(query_id +1, memcached_query_id(memc));
}
test_return_t enable_consistent_crc(memcached_st *memc)
{
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT));
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
+
test_return_t rc;
- memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
- memcached_hash_t hash;
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
if ((rc= pre_crc(memc)) != TEST_SUCCESS)
+ {
return rc;
+ }
- value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
- test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
-
- hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
- if (hash != MEMCACHED_HASH_CRC)
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_CRC)
+ {
return TEST_SKIPPED;
+ }
return TEST_SUCCESS;
}
test_return_t enable_consistent_hsieh(memcached_st *memc)
{
test_return_t rc;
- memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
- memcached_hash_t hash;
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT);
if ((rc= pre_hsieh(memc)) != TEST_SUCCESS)
{
return rc;
}
- value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
- test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
-
- hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
- if (hash != MEMCACHED_HASH_HSIEH)
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_HSIEH)
+ {
return TEST_SKIPPED;
-
+ }
return TEST_SUCCESS;
}
{
continue;
}
- test_true_hint(ret == MEMCACHED_SUCCESS and value != NULL, memcached_last_error_message(memc));
+ test_true(ret == MEMCACHED_SUCCESS and value != NULL);
switch (count)
{
case 0: /* FALLTHROUGH */
test_return_t pre_behavior_ketama(memcached_st *memc)
{
- memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1);
- test_compare(MEMCACHED_SUCCESS, rc);
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1));
- uint64_t value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA);
- test_compare(value, uint64_t(1));
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA), uint64_t(1));
return TEST_SUCCESS;
}