if (server->root->poll_timeout == 0)
{
return memcached_set_error(*server, MEMCACHED_TIMEOUT, MEMCACHED_AT,
- memcached_literal_param("The time to wait for a connection to be established was set to zero, which means it will always timeout (MEMCACHED_TIMEOUT)."));
+ memcached_literal_param("The time to wait for a connection to be established was set to zero which produces a timeout to every call to poll()."));
}
while (--loop_max) // Should only loop on cases of ERESTART or EINTR
*/
#include <libmemcached/common.h>
+
+#include "libmemcached/assert.hpp"
+
#include <cerrno>
#include <cstdarg>
#include <cstdio>
memcached_error_free(memc);
}
- // For memory allocation we use our error since it is a bit more specific
- if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO)
+ if (memcached_fatal(rc))
{
- rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- }
+ // For memory allocation we use our error since it is a bit more specific
+ if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO)
+ {
+ rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ }
- if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
- {
- local_errno= ENOMEM;
- }
+ if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
+ {
+ local_errno= ENOMEM;
+ }
- if (rc == MEMCACHED_ERRNO and not local_errno)
- {
- local_errno= errno;
- rc= MEMCACHED_ERRNO;
- }
+ if (rc == MEMCACHED_ERRNO and not local_errno)
+ {
+ local_errno= errno;
+ rc= MEMCACHED_ERRNO;
+ }
- if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN)
- {
- rc= MEMCACHED_CONNECTION_FAILURE;
- }
+ if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN)
+ {
+ rc= MEMCACHED_CONNECTION_FAILURE;
+ }
- if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET)
- {
- rc= MEMCACHED_CONNECTION_FAILURE;
- }
+ if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET)
+ {
+ rc= MEMCACHED_CONNECTION_FAILURE;
+ }
- if (local_errno == EINVAL)
- {
- rc= MEMCACHED_INVALID_ARGUMENTS;
- }
+ if (local_errno == EINVAL)
+ {
+ rc= MEMCACHED_INVALID_ARGUMENTS;
+ }
- if (local_errno == ECONNREFUSED)
- {
- rc= MEMCACHED_CONNECTION_FAILURE;
- }
+ if (local_errno == ECONNREFUSED)
+ {
+ rc= MEMCACHED_CONNECTION_FAILURE;
+ }
- memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
- if (error == NULL) // Bad business if this happens
- {
- return;
- }
+ if (rc == MEMCACHED_TIMEOUT)
+ {
+ }
- error->root= &memc;
- error->query_id= memc.query_id;
- error->rc= rc;
- error->local_errno= local_errno;
+ memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
+ if (error == NULL) // Bad business if this happens
+ {
+ assert_msg(error, "libmemcached_xmalloc() failed to allocate a memcached_error_t");
+ return;
+ }
- const char *errmsg_ptr;
- char errmsg[MAX_ERROR_LENGTH];
- errmsg[0]= 0;
- errmsg_ptr= errmsg;
+ error->root= &memc;
+ error->query_id= memc.query_id;
+ error->rc= rc;
+ error->local_errno= local_errno;
- if (local_errno)
- {
+ const char *errmsg_ptr;
+ char errmsg[MAX_ERROR_LENGTH];
+ errmsg[0]= 0;
+ errmsg_ptr= errmsg;
+
+ if (local_errno)
+ {
#if defined(STRERROR_R_CHAR_P) && STRERROR_R_CHAR_P
- errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
+ errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
#elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R
- strerror_r(local_errno, errmsg, sizeof(errmsg));
- errmsg_ptr= errmsg;
+ strerror_r(local_errno, errmsg, sizeof(errmsg));
+ errmsg_ptr= errmsg;
#elif defined(HAVE_STRERROR) && HAVE_STRERROR
- snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno));
- errmsg_ptr= errmsg;
+ snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno));
+ errmsg_ptr= errmsg;
#endif
- }
+ }
- if (str and str->size and local_errno)
- {
- error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s",
- error->root,
- memcached_strerror(&memc, rc),
- errmsg_ptr,
- memcached_string_printf(*str), at);
- }
- else if (local_errno)
- {
- error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s",
- error->root,
- memcached_strerror(&memc, rc),
- errmsg_ptr,
- at);
- }
- else if (rc == MEMCACHED_PARSE_ERROR and str and str->size)
- {
- error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s",
- error->root,
- int(str->size), str->c_str, at);
- }
- else if (str and str->size)
- {
- error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s",
- error->root,
- memcached_strerror(&memc, rc),
- int(str->size), str->c_str, at);
- }
- else
- {
- error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s",
- error->root,
- memcached_strerror(&memc, rc), at);
- }
+ if (str and str->size and local_errno)
+ {
+ error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s",
+ error->root,
+ memcached_strerror(&memc, rc),
+ errmsg_ptr,
+ memcached_string_printf(*str), at);
+ }
+ else if (local_errno)
+ {
+ error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s",
+ error->root,
+ memcached_strerror(&memc, rc),
+ errmsg_ptr,
+ at);
+ }
+ else if (rc == MEMCACHED_PARSE_ERROR and str and str->size)
+ {
+ error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s",
+ error->root,
+ int(str->size), str->c_str, at);
+ }
+ else if (str and str->size)
+ {
+ error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s",
+ error->root,
+ memcached_strerror(&memc, rc),
+ int(str->size), str->c_str, at);
+ }
+ else
+ {
+ error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s",
+ error->root,
+ memcached_strerror(&memc, rc), at);
+ }
- error->next= memc.error_messages;
- memc.error_messages= error;
+ error->next= memc.error_messages;
+ memc.error_messages= error;
+ }
#if 0
if (error_log_fd == -1)
memcached_return_t memcached_set_error(Memcached& memc, memcached_return_t rc, const char *at, memcached_string_t& str)
{
assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
- if (memcached_fatal(rc) == false)
+ if (memcached_fatal(rc))
{
- return rc;
+ _set(memc, &str, rc, at);
}
- _set(memc, &str, rc, at);
-
return rc;
}
memcached_string_t error_host= { hostname_port_message, size_t(size) };
assert_msg(self.root, "Programmer error, root was not set on instance");
- if (self.root == NULL)
+ if (self.root)
{
- return rc;
+ _set(*self.root, &error_host, rc, at);
+ _set(self, (*self.root));
+ assert(self.root->error_messages);
+ assert(self.error_messages);
+ assert(self.error_messages->rc == self.root->error_messages->rc);
}
- _set(*self.root, &error_host, rc, at);
- _set(self, (*self.root));
- assert(self.root->error_messages);
- assert(self.error_messages);
- assert(self.error_messages->rc == self.root->error_messages->rc);
-
return rc;
}
memcached_string_t error_host= { hostname_port, size};
- if (self.root == NULL)
+ if (self.root)
{
- return rc;
+ _set(*self.root, &error_host, rc, at);
+ _set(self, *self.root);
}
- _set(*self.root, &error_host, rc, at);
- _set(self, *self.root);
-
return rc;
}
{
if (memc->error_messages)
{
- if (memc->error_messages->size == 0)
+ if (memc->error_messages->size and memc->error_messages->message[0])
{
return memc->error_messages->message;
}
{
*error= MEMCACHED_NOTFOUND;
}
-
if (value == NULL)
{
if (ptr->get_key_failure and *error == MEMCACHED_NOTFOUND)
if (number_of_keys == 0)
{
- return memcached_set_error(*ptr, MEMCACHED_NOTFOUND, MEMCACHED_AT, memcached_literal_param("number_of_keys was zero"));
+ return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Numbers of keys provided was zero"));
}
- if (memcached_failed(memcached_key_test(*ptr, keys, key_length, number_of_keys)))
+ if (memcached_failed((rc= memcached_key_test(*ptr, keys, key_length, number_of_keys))))
{
- return memcached_last_error(ptr);
+ assert(memcached_last_error(ptr) == rc);
+
+ return rc;
}
bool is_group_key_set= false;
bool flush= (number_of_keys == 1);
+ if (memcached_failed(rc= memcached_key_test(*ptr, keys, key_length, number_of_keys)))
+ {
+ return rc;
+ }
+
/*
If a server fails we warn about errors and start all over with sending keys
to the server.
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
}
+#if 0
{
memcached_return_t vk= memcached_validate_key_length(key_length[x], ptr->flags.binary_protocol);
- if (vk != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc= memcached_key_test(*memc, (const char **)&key, &key_length, 1)))
{
+ memcached_set_error(ptr, vk, MEMCACHED_AT, memcached_literal_param("Key was too long."));
+
if (x > 0)
{
memcached_io_reset(instance);
return vk;
}
}
+#endif
request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->_namespace)));
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
return io_wait(instance, MEM_WRITE);
}
+memcached_return_t memcached_io_wait_for_read(memcached_instance_st* instance)
+{
+ return io_wait(instance, MEM_READ);
+}
+
static memcached_return_t _io_fill(memcached_instance_st* instance)
{
ssize_t data_read;
libmemcached_io_vector_st vector[],
const size_t number_of, const bool with_flush);
-memcached_return_t memcached_io_wait_for_write(memcached_instance_st* ptr);
+memcached_return_t memcached_io_wait_for_write(memcached_instance_st*);
+memcached_return_t memcached_io_wait_for_read(memcached_instance_st*);
void memcached_io_reset(memcached_instance_st* ptr);
#include <libmemcached/common.h>
+static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool)
+{
+ if (key_length == 0)
+ {
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+
+ // No one ever reimplemented MEMCACHED to use keys longer then the original ascii length
+#if 0
+ if (binary)
+ {
+ if (key_length > 0xffff)
+ {
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+ }
+ else
+#endif
+ {
+ if (key_length >= MEMCACHED_MAX_KEY)
+ {
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
memcached_return_t memcached_key_test(memcached_st &memc,
const char * const *keys,
const size_t *key_length,
size_t number_of_keys)
{
+ if (number_of_keys == 0)
+ {
+ return memcached_set_error(memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Numbers of keys provided was zero"));
+ }
+
if (keys == NULL or key_length == NULL)
{
return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key was NULL or length of key was zero."));
}
+ const bool is_binary= memcached_flag(memc, MEMCACHED_FLAG_BINARY_PROTOCOL);
+
// If we don't need to verify the key, or we are using the binary protoocol,
// we just check the size of the key
- if (memc.flags.verify_key == false or memc.flags.binary_protocol == true)
- {
- for (size_t x= 0; x < number_of_keys; x++)
- {
- // We should set binary key, but the memcached server is broken for
- // longer keys at the moment.
- memcached_return_t rc= memcached_validate_key_length(*(key_length +x), false /* memc.flags.binary_protocol */);
- if (memcached_failed(rc))
- {
- return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long."));
- }
- }
-
- return MEMCACHED_SUCCESS;
- }
-
- for (size_t x= 0; x < number_of_keys; x++)
+ for (size_t x= 0; x < number_of_keys; ++x)
{
- memcached_return_t rc= memcached_validate_key_length(*(key_length + x), false);
+ // We should set binary key, but the memcached server is broken for
+ // longer keys at the moment.
+ memcached_return_t rc= memcached_validate_key_length(*(key_length +x), false /* memc.flags.binary_protocol */);
if (memcached_failed(rc))
{
return memcached_set_error(memc, rc, MEMCACHED_AT, memcached_literal_param("Key provided was too long."));
}
-
- for (size_t y= 0; y < *(key_length + x); y++)
+
+ if (memc.flags.verify_key and is_binary == false)
{
- if ((isgraph(keys[x][y])) == 0)
+ for (size_t y= 0; y < *(key_length +x); ++y)
{
- return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key provided had invalid character."));
+ if ((isgraph(keys[x][y])) == 0)
+ {
+ return memcached_set_error(memc, MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_AT, memcached_literal_param("Key provided had invalid character."));
+ }
}
}
}
const size_t *key_length,
size_t number_of_keys);
-static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary)
-{
- if (key_length == 0)
- {
- return MEMCACHED_BAD_KEY_PROVIDED;
- }
-
- if (binary)
- {
- if (key_length > 0xffff)
- {
- return MEMCACHED_BAD_KEY_PROVIDED;
- }
- }
- else
- {
- if (key_length >= MEMCACHED_MAX_KEY)
- {
- return MEMCACHED_BAD_KEY_PROVIDED;
- }
- }
-
- return MEMCACHED_SUCCESS;
-}
memcached_return_t rc;
protocol_binary_response_header header;
+ assert(memcached_is_binary(instance->root));
+
if ((rc= memcached_safe_read(instance, &header.bytes, sizeof(header.bytes))) != MEMCACHED_SUCCESS)
{
WATCHPOINT_ERROR(rc);
return memcached_set_error(*instance, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT);
}
- /* We may have old commands in the buffer not set, first purge */
+ /* We may have old commands in the buffer not sent, first purge */
if ((instance->root->flags.no_block) and (memcached_is_processing_input(instance->root) == false))
{
(void)memcached_io_write(instance);
}
+ /* Before going into loop wait to see if we have any IO waiting for us */
+ if (0)
+ {
+ memcached_return_t read_rc= memcached_io_wait_for_read(instance);
+ fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, memcached_strerror(NULL, read_rc));
+ }
+
/*
* The previous implementation purged all pending requests and just
* returned the last one. Purge all pending messages to ensure backwards
return MEMCACHED_SUCCESS;
}
-char *memcached_stat_get_value(const memcached_st *, memcached_stat_st *memc_stat,
+char *memcached_stat_get_value(const memcached_st* shell, memcached_stat_st *memc_stat,
const char *key, memcached_return_t *error)
{
memcached_return_t not_used;
}
else
{
- *error= MEMCACHED_NOTFOUND;
+ Memcached* memc= (Memcached*)memcached2Memcached(shell);
+ *error= memcached_set_error(*memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid key provided"));
return NULL;
}
if (length >= SMALL_STRING_LEN || length < 0)
{
- *error= MEMCACHED_FAILURE;
+ Memcached* memc= (Memcached*)memcached2Memcached(shell);
+ *error= memcached_set_error(*memc, MEMCACHED_FAILURE, MEMCACHED_AT, memcached_literal_param("Internal failure occured with buffer, please report this bug."));
return NULL;
}
if (args)
{
args_length= strlen(args);
- rc= memcached_validate_key_length(args_length, self->flags.binary_protocol);
- if (memcached_failed(rc))
+ if (memcached_failed(rc= memcached_key_test(*self, (const char **)&args, &args_length, 1)))
{
*error= memcached_set_error(*self, rc, MEMCACHED_AT);
return NULL;
if (args)
{
args_length= strlen(args);
- rc= memcached_validate_key_length(args_length, memc.flags.binary_protocol);
+ rc= memcached_key_test(*memc_ptr, (const char **)&args, &args_length, 1);
}
if (memcached_success(rc))
return rc;
}
- if (memcached_failed(rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol)))
+ if (memcached_failed(rc= memcached_key_test(*ptr, (const char **)&key, &key_length, 1)))
{
- return rc;
+ return memcached_set_error(*ptr, rc, MEMCACHED_AT);
}
uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length);
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
-#serial 19
+#serial 20
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
AC_DEFUN([AX_PTHREAD], [
ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
;;
- darwin12*)
- ax_pthread_flags="$ax_pthread_flags"
- ;;
-
darwin*)
ax_pthread_flags="-pthread $ax_pthread_flags"
;;
LIBS="$save_LIBS"
CFLAGS="$save_CFLAGS"
- # More AIX lossage: must compile with xlc_r or cc_r
- if test x"$GCC" != xyes; then
- AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
- else
- PTHREAD_CC=$CC
+ # More AIX lossage: compile with *_r variant
+ if test "x$GCC" != xyes; then
+ case $host_os in
+ aix*)
+ AS_CASE(["x/$CC"],
+ [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
+ [#handle absolute path differently from PATH based program lookup
+ AS_CASE(["x$CC"],
+ [x/*],
+ [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
+ [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
+ ;;
+ esac
fi
-else
- PTHREAD_CC="$CC"
fi
+test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
+
AC_SUBST(PTHREAD_LIBS)
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_CC)
test_compare(MEMCACHED_SUCCESS,
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, true));
test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set()
+ ASSERT_TRUE(memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY));
/* All keys are valid in the binary protocol (except for length) */
if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == false)
const char *key= "mine";
char *value;
- /* Make sure be default none exists */
+ /* Make sure by default none exists */
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_null(value);
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_true(value);
- test_memcmp(value, key, 4);
+ test_memcmp(value, key, strlen(key));
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
/* Test that we can turn it off */
value= (char *)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_true(value);
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
- test_memcmp(value, key, 4);
+ test_memcmp(value, key, strlen(key));
/* Set to Zero, and then Set to something too large */
{
test_compare(MEMCACHED_SUCCESS,
memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL));
- value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_null(value);
- test_compare(MEMCACHED_SUCCESS, rc);
+ ASSERT_NULL_(memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc), "Setting namespace to NULL did not work");
/* Test a long key for failure */
/* TODO, extend test to determine based on setting, what result should be */
{
memcached_return_t rc;
const char *key= "mine";
- char *value;
// Make sure we default to a null namespace
- value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_null(value);
+ char* value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
+ ASSERT_NULL_(value, "memc had a value for namespace when none should exist");
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
/* Test a clean set */
memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, (void *)key));
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_true(value);
- test_memcmp(value, key, 4);
+ ASSERT_TRUE(value);
+ test_memcmp(value, key, strlen(key));
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
return TEST_SUCCESS;