# the COPYING file in this directory for full text.
AC_PREREQ(2.59)
-AC_INIT([libmemcached],[0.50],[http://libmemcached.org/])
+AC_INIT([libmemcached],[0.51],[http://libmemcached.org/])
AC_CONFIG_SRCDIR([libmemcached/memcached.cc])
AC_CONFIG_AUX_DIR(config)
AC_CHECK_PROGS([LEX], ['flex'], [:])
#shared library versioning
-MEMCACHED_UTIL_LIBRARY_VERSION=2:0:0
+MEMCACHED_UTIL_LIBRARY_VERSION=2:1:1
MEMCACHED_PROTOCAL_LIBRARY_VERSION=0:0:0
-MEMCACHED_LIBRARY_VERSION=8:0:0
+MEMCACHED_LIBRARY_VERSION=8:1:1
# | | |
# +------+ | +---+
# | | |
#include <libmemcached/response.h>
#include <libmemcached/namespace.h>
+#ifdef __cplusplus
+#include <libmemcached/assert.hpp>
+#endif
+
/* string value */
struct memcached_continuum_item_st
{
char str_port[NI_MAXSERV];
int length= snprintf(str_port, NI_MAXSERV, "%u", (uint32_t)server->port);
if (length >= NI_MAXSERV || length < 0)
+ {
return MEMCACHED_FAILURE;
+ }
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
{
- rc= MEMCACHED_WRITE_FAILURE;
+ rc= memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
goto error;
}
WATCHPOINT_ASSERT(count);
WATCHPOINT_ASSERT(vector);
- if ((rc= memcached_connect(ptr)) != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc= memcached_connect(ptr)))
{
WATCHPOINT_ERROR(rc);
+ assert_msg(ptr->error_messages, "memcached_connect() returned an error but the memcached_server_write_instance_st showed none.");
return rc;
}
command_length+= vector->length;
}
- if (sent_length == -1 || (size_t)sent_length != command_length)
+ if (sent_length == -1 or size_t(sent_length) != command_length)
{
rc= MEMCACHED_WRITE_FAILURE;
WATCHPOINT_ERROR(rc);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
{
- return MEMCACHED_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
}
rc= memcached_do(instance, buffer, (size_t)send_length, true);
memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, const char *str, size_t length)
{
assert(rc != MEMCACHED_ERRNO);
+ assert(rc != MEMCACHED_SOME_ERRORS);
memcached_string_t tmp= { str, length };
return memcached_set_error(self, rc, at, tmp);
}
memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str)
{
assert(rc != MEMCACHED_ERRNO);
+ assert(rc != MEMCACHED_SOME_ERRORS);
if (memcached_success(rc))
return MEMCACHED_SUCCESS;
memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at)
{
assert(rc != MEMCACHED_ERRNO);
+ assert(rc != MEMCACHED_SOME_ERRORS);
if (memcached_success(rc))
return MEMCACHED_SUCCESS;
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
{
- return MEMCACHED_FAILURE;
+ return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
}
rc= memcached_do(instance, buffer, (size_t)send_length, true);
if (sort_host_length >= MEMCACHED_MAX_HOST_SORT_LENGTH || sort_host_length < 0)
{
- return MEMCACHED_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
}
#ifdef DEBUG
printf("update_continuum: key is %s\n", sort_host);
if (sort_host_length >= MEMCACHED_MAX_HOST_SORT_LENGTH || sort_host_length < 0)
{
- return MEMCACHED_FAILURE;
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
}
WATCHPOINT_ASSERT(sort_host_length);
}
else if (not strcmp("pid", key))
{
- memc_stat->pid= strtoul(value, (char **)NULL, 10);
+ int64_t temp= strtoll(value, (char **)NULL, 10);
+
+ if (temp <= INT32_MAX and ( sizeof(pid_t) == sizeof(int32_t) ))
+ {
+ memc_stat->pid= temp;
+ }
+ else if (temp > -1)
+ {
+ memc_stat->pid= temp;
+ }
+ else
+ {
+ // If we got a value less then -1 then something went wrong in the
+ // protocol
+ }
}
else if (not strcmp("uptime", key))
{
if (not memcmp("pid", key, sizeof("pid") -1))
{
- length= snprintf(buffer, SMALL_STRING_LEN,"%lu", memc_stat->pid);
+ length= snprintf(buffer, SMALL_STRING_LEN,"%lld", (signed long long)memc_stat->pid);
}
else if (not memcmp("uptime", key, sizeof("uptime") -1))
{
memcached_server_write_instance_st instance,
struct local_context *check)
{
- memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
int send_length;
if (args)
- send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "stats %s\r\n", args);
+ {
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats %s\r\n", args);
+ }
else
- send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "stats\r\n");
+ {
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats\r\n");
+ }
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
- return MEMCACHED_WRITE_FAILURE;
-
- rc= memcached_do(instance, buffer, (size_t)send_length, true);
- if (rc != MEMCACHED_SUCCESS)
- goto error;
-
- while (1)
{
- rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
+ }
- if (rc == MEMCACHED_STAT)
+ memcached_return_t rc= memcached_do(instance, buffer, (size_t)send_length, true);
+ if (memcached_success(rc))
+ {
+ while ((rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL)) == MEMCACHED_STAT)
{
char *string_ptr, *end_ptr;
char *key, *value;
check->context);
}
}
- else
- {
- break;
- }
}
-error:
if (rc == MEMCACHED_END)
return MEMCACHED_SUCCESS;
else
memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_return_t *error)
{
memcached_return_t rc;
- if ((rc= initialize_query(self)) != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc= initialize_query(self)))
{
if (error)
*error= rc;
temp_return= ascii_stats_fetch(stat_instance, args, instance, NULL);
}
- if (temp_return != MEMCACHED_SUCCESS)
+ if (memcached_failed(temp_return))
+ {
rc= MEMCACHED_SOME_ERRORS;
+ }
}
if (error)
unsigned long connection_structures;
unsigned long curr_connections;
unsigned long curr_items;
- unsigned long pid;
+ pid_t pid;
unsigned long pointer_size;
unsigned long rusage_system_microseconds;
unsigned long rusage_system_seconds;
(ptr->flags.no_reply) ? " noreply" : "");
if (check_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || check_length < 0)
{
- rc= MEMCACHED_WRITE_FAILURE;
+ rc= memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
memcached_io_reset(instance);
return rc;
ptr->flags.no_reply ? " noreply" : "");
if ((size_t)check_length >= MEMCACHED_DEFAULT_COMMAND_SIZE -size_t(buffer_ptr - buffer) || check_length < 0)
{
- rc= MEMCACHED_WRITE_FAILURE;
+ rc= memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
memcached_io_reset(instance);
return rc;
if (not memc_ptr)
{
*ret= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- return pid;
+ return -1;
}
memcached_return_t rc= memcached_server_add(memc_ptr, hostname, port);
if (memcached_success(rc))
{
memcached_stat_st *stat= memcached_stat(memc_ptr, NULL, &rc);
- if (stat and stat->pid > 0)
+ if (memcached_success(rc) and stat and stat->pid != -1)
{
pid= stat->pid;
}
- else if (memcached_failed(rc) and rc == MEMCACHED_SOME_ERRORS)
+ else if (memcached_success(rc))
+ {
+ rc= MEMCACHED_UNKNOWN_STAT_KEY; // Something went wrong if this happens
+ }
+ else if (rc == MEMCACHED_SOME_ERRORS) // Generic answer, we will now find the specific reason (if one exists)
{
memcached_server_instance_st instance=
memcached_server_instance_by_position(memc_ptr, 0);
+ assert_msg(instance and instance->error_messages, " ");
if (instance and instance->error_messages)
{
rc= memcached_server_error_return(instance);
}
}
- else if (memcached_success(rc))
- {
- rc= MEMCACHED_UNKNOWN_STAT_KEY; // Something went wrong if this happens
- }
memcached_stat_free(memc_ptr, stat);
}
memcached_server_instance_st instance=
memcached_server_instance_by_position(memc_ptr, 0);
+ assert_msg(instance and instance->error_messages, " ");
if (instance and instance->error_messages)
{
rc= memcached_server_error_return(instance);
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"verbosity %u\r\n", verbosity);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0)
- return MEMCACHED_WRITE_FAILURE;
+ {
+ return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
+ memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)"));
+ }
struct context_st context = { (size_t)send_length, buffer };
return true;
}
-
-void server_shutdown(server_startup_st *construct)
-{
- if (not construct)
- return;
-
- construct->shutdown();
-}
}
servers.clear();
}
+
+void server_shutdown(server_startup_st *construct)
+{
+ if (not construct)
+ return;
+
+ construct->shutdown();
+}
return TEST_SUCCESS;
}
-#ifdef HAVE_LIBMEMCACHEDUTIL
-
struct test_pool_context_st {
memcached_pool_st* pool;
memcached_st* mmc;
return TEST_SUCCESS;
}
+static test_return_t getpid_connection_failure_test(memcached_st *memc)
+{
+ memcached_return_t rc;
+ memcached_server_instance_st instance=
+ memcached_server_instance_by_position(memc, 0);
+
+ // Test both the version that returns a code, and the one that does not.
+ test_true(libmemcached_util_getpid(memcached_server_name(instance),
+ memcached_server_port(instance) -1, NULL) == -1);
+
+ test_true(libmemcached_util_getpid(memcached_server_name(instance),
+ memcached_server_port(instance) -1, &rc) == -1);
+ test_compare_got(MEMCACHED_CONNECTION_FAILURE, rc, memcached_strerror(memc, rc));
+
+ return TEST_SUCCESS;
+}
+
+
+static test_return_t getpid_test(memcached_st *memc)
+{
+ memcached_return_t rc;
+ memcached_server_instance_st instance=
+ memcached_server_instance_by_position(memc, 0);
+
+ // Test both the version that returns a code, and the one that does not.
+ test_true(libmemcached_util_getpid(memcached_server_name(instance),
+ memcached_server_port(instance), NULL) > -1);
+
+ test_true(libmemcached_util_getpid(memcached_server_name(instance),
+ memcached_server_port(instance), &rc) > -1);
+ test_compare(MEMCACHED_SUCCESS, rc);
+
+ return TEST_SUCCESS;
+}
+
static test_return_t ping_test(memcached_st *memc)
{
memcached_return_t rc;
return TEST_SUCCESS;
}
-#endif
#if 0
{"analyzer", 1, (test_callback_fn*)analyzer_test},
{"connectionpool", 1, (test_callback_fn*)connection_pool_test },
{"memcached_pool_test", 1, (test_callback_fn*)memcached_pool_test },
- {"ping", 1, (test_callback_fn*)ping_test },
{"test_get_last_disconnect", 1, (test_callback_fn*)test_get_last_disconnect},
{"verbosity", 1, (test_callback_fn*)test_verbosity},
{"test_server_failure", 1, (test_callback_fn*)test_server_failure},
{0, 0, 0}
};
+test_st libmemcachedutil_tests[] ={
+ {"libmemcached_util_ping()", 1, (test_callback_fn*)ping_test },
+ {"libmemcached_util_getpid()", 1, (test_callback_fn*)getpid_test },
+ {"libmemcached_util_getpid(MEMCACHED_CONNECTION_FAILURE)", 1, (test_callback_fn*)getpid_connection_failure_test },
+ {0, 0, 0}
+};
+
test_st basic_tests[] ={
{"init", 1, (test_callback_fn*)basic_init_test},
{"clone", 1, (test_callback_fn*)basic_clone_test},
#if 0
{"hash_sanity", 0, 0, hash_sanity},
#endif
+ {"libmemcachedutil", 0, 0, libmemcachedutil_tests},
{"basic", 0, 0, basic_tests},
{"hsieh_availability", 0, 0, hsieh_availability},
{"murmur_availability", 0, 0, murmur_availability},