-0.38
+0.38
+
+ * Functions used for callbacks are now given const memcached_st.
* Added MEMCACHED_BEHAVIOR_CORK.
/**
* Callback function to count the number of results
*/
-static memcached_return_t callback_counter(memcached_st *ptr,
- memcached_result_st *result,
- void *context)
+static memcached_return_t callback_counter(const memcached_st *ptr,
+ memcached_result_st *result,
+ void *context)
{
(void)ptr;
(void)result;
static char *opt_hash= NULL;
/* Print the keys and counter how many were found */
-static memcached_return_t key_printer(memcached_st *ptr __attribute__((unused)),
+static memcached_return_t key_printer(const memcached_st *ptr __attribute__((unused)),
const char *key, size_t key_length,
void *context __attribute__((unused)))
{
#include "common.h"
-void libmemcached_free(memcached_st *ptr, void *mem)
+void libmemcached_free(const memcached_st *ptr, void *mem)
{
(void) ptr;
free(mem);
}
-void *libmemcached_malloc(memcached_st *ptr, size_t size)
+void *libmemcached_malloc(const memcached_st *ptr, size_t size)
{
(void) ptr;
return malloc(size);
}
-void *libmemcached_realloc(memcached_st *ptr, void *mem, size_t size)
+void *libmemcached_realloc(const memcached_st *ptr, void *mem, size_t size)
{
(void) ptr;
return realloc(mem, size);
}
-void *libmemcached_calloc(memcached_st *ptr, size_t nelem, size_t size)
+void *libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size)
{
if (ptr->call_malloc != libmemcached_malloc)
{
ptr->call_calloc= libmemcached_calloc;
}
else if (mem_malloc == NULL || mem_free == NULL || mem_realloc == NULL || mem_calloc == NULL)
+ {
return MEMCACHED_FAILURE;
+ }
else
{
ptr->call_malloc= mem_malloc;
return MEMCACHED_SUCCESS;
}
-void memcached_get_memory_allocators(memcached_st *ptr,
+void memcached_get_memory_allocators(const memcached_st *ptr,
memcached_malloc_fn *mem_malloc,
memcached_free_fn *mem_free,
memcached_realloc_fn *mem_realloc,
memcached_calloc_fn mem_calloc);
LIBMEMCACHED_API
-void memcached_get_memory_allocators(memcached_st *ptr,
+void memcached_get_memory_allocators(const memcached_st *ptr,
memcached_malloc_fn *mem_malloc,
memcached_free_fn *mem_free,
memcached_realloc_fn *mem_realloc,
memcached_calloc_fn *mem_calloc);
+LIBMEMCACHED_LOCAL
+void libmemcached_free(const memcached_st *ptr, void *mem);
+
+LIBMEMCACHED_LOCAL
+void *libmemcached_malloc(const memcached_st *ptr, const size_t size);
+
+LIBMEMCACHED_LOCAL
+void *libmemcached_realloc(const memcached_st *ptr, void *mem, const size_t size);
+
+LIBMEMCACHED_LOCAL
+void *libmemcached_calloc(const memcached_st *ptr, size_t nelem, size_t size);
+
#ifdef __cplusplus
}
if (curr_time.tv_sec < ptr->next_retry)
{
- if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
+ memcached_st *root= (memcached_st *)ptr->root;
+ // @todo fix this by fixing behavior to no longer make use of
+ // memcached_st
+ if (memcached_behavior_get(root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS))
{
- run_distribution(ptr->root);
+ run_distribution(root);
}
- ptr->root->last_disconnected_server = ptr;
+ root->last_disconnected_server = ptr;
+
return MEMCACHED_SERVER_MARKED_DEAD;
}
}
WATCHPOINT_ASSERT(0);
}
- unlikely ( rc != MEMCACHED_SUCCESS) ptr->root->last_disconnected_server = ptr;
+ unlikely ( rc != MEMCACHED_SUCCESS)
+ {
+ //@todo create interface around last_discontected_server
+ memcached_st *root= (memcached_st *)ptr->root;
+ root->last_disconnected_server = ptr;
+ }
LIBMEMCACHED_MEMCACHED_CONNECT_END();
instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
- memcached_server_create(ptr, instance);
/* TODO check return type */
(void)memcached_server_create_with(ptr, instance, list[x].hostname,
list[x].port, list[x].weight, list[x].type);
return run_distribution(ptr);
}
+/**
+ @todo allow lists to query themselves even if they lack a root
+*/
memcached_return_t memcached_server_remove(memcached_server_st *st_ptr)
{
uint32_t x, host_index;
- memcached_st *ptr= st_ptr->root;
- memcached_server_st *list= memcached_server_list(ptr);
+ memcached_st *root= (memcached_st *)st_ptr->root;
+ memcached_server_st *list;
- for (x= 0, host_index= 0; x < memcached_server_count(ptr); x++)
+ if (root == NULL)
+ return MEMCACHED_FAILURE;
+
+ list= memcached_server_list(root);
+
+ for (x= 0, host_index= 0; x < memcached_server_count(root); x++)
{
if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH) != 0 || list[x].port != st_ptr->port)
{
host_index++;
}
}
- ptr->number_of_hosts= host_index;
+ root->number_of_hosts= host_index;
if (st_ptr->address_info)
{
freeaddrinfo(st_ptr->address_info);
st_ptr->address_info= NULL;
}
- run_distribution(ptr);
+ run_distribution(root);
return MEMCACHED_SUCCESS;
}
extern "C" {
#endif
-LIBMEMCACHED_LOCAL
-void libmemcached_free(memcached_st *ptr, void *mem);
-LIBMEMCACHED_LOCAL
-void *libmemcached_malloc(memcached_st *ptr, const size_t size);
-LIBMEMCACHED_LOCAL
-void *libmemcached_realloc(memcached_st *ptr, void *mem, const size_t size);
-LIBMEMCACHED_LOCAL
-void *libmemcached_calloc(memcached_st *ptr, size_t nelem, size_t size);
-
#ifdef __cplusplus
}
#endif
*/
memcached_callback_st cb= *ptr->root->callbacks;
- memcached_set_processing_input(ptr->root, true);
+ memcached_set_processing_input((memcached_st *)ptr->root, true);
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
memcached_return_t error;
+ memcached_st *root= (memcached_st *)ptr->root;
error= memcached_response(ptr, buffer, sizeof(buffer),
- &ptr->root->result);
+ &root->result);
- memcached_set_processing_input(ptr->root, false);
+ memcached_set_processing_input(root, false);
if (error == MEMCACHED_SUCCESS)
{
for (unsigned int x= 0; x < cb.number_of_callback; x++)
{
- error= (*cb.callback[x])(ptr->root, &ptr->root->result, cb.context);
+ error= (*cb.callback[x])(ptr->root, &root->result, cb.context);
if (error != MEMCACHED_SUCCESS)
break;
}
strstm << port;
tmp_str.append(strstm.str());
memcached_server_st *server= memcached_servers_parse(tmp_str.c_str());
+
memcached_return_t rc= memcached_server_remove(server);
+
return (rc == MEMCACHED_SUCCESS);
}
{
uint32_t x;
memcached_return_t ret= MEMCACHED_SUCCESS;
+ memcached_st *root= (memcached_st *)ptr->root;
if (memcached_is_purging(ptr->root) || /* already purging */
(memcached_server_response_count(ptr) < ptr->root->io_msg_watermark &&
/* memcached_io_write and memcached_response may call memcached_purge
so we need to be able stop any recursion.. */
- memcached_set_purging(ptr->root, true);
+ memcached_set_purging(root, true);
WATCHPOINT_ASSERT(ptr->fd != -1);
/* Force a flush of the buffer to ensure that we don't have the n-1 pending
requests buffered up.. */
if (memcached_io_write(ptr, NULL, 0, 1) == -1)
{
- memcached_set_purging(ptr->root, true);
+ memcached_set_purging(root, true);
return MEMCACHED_WRITE_FAILURE;
}
* data to be sent from the server (the commands was in the output buffer
* and just flushed
*/
- int32_t timeo= ptr->root->poll_timeout;
- ptr->root->poll_timeout= 2000;
+ const int32_t timeo= ptr->root->poll_timeout;
+ root->poll_timeout= 2000;
- result_ptr= memcached_result_create(ptr->root, &result);
+ result_ptr= memcached_result_create(root, &result);
WATCHPOINT_ASSERT(result_ptr);
for (x= 0; x < no_msg; x++)
}
memcached_result_free(result_ptr);
- ptr->root->poll_timeout= timeo;
+ root->poll_timeout= timeo;
}
- memcached_set_purging(ptr->root, false);
+ memcached_set_purging(root, false);
return ret;
}
memcached_server_response_decrement(ptr);
if (result == NULL)
- result = &ptr->root->result;
+ {
+ memcached_st *root= (memcached_st *)ptr->root;
+ result = &root->result;
+ }
memcached_return_t rc;
if (ptr->root->flags.binary_protocol)
memcached_result_st *memcached_result_create(memcached_st *memc,
memcached_result_st *ptr)
{
- WATCHPOINT_ASSERT(memc && memc->options.is_initialized);
+ WATCHPOINT_ASSERT(memc);
+ WATCHPOINT_ASSERT(memc->options.is_initialized);
/* Saving malloc calls :) */
if (ptr)
*/
#include "common.h"
-memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr)
+static memcached_server_st *_server_create(const memcached_st *memc, memcached_server_st *ptr)
{
if (ptr == NULL)
{
return ptr;
}
-memcached_server_st *memcached_server_create_with(memcached_st *memc, memcached_server_st *host,
+memcached_server_st *memcached_server_create_with(const memcached_st *memc, memcached_server_st *host,
const char *hostname, in_port_t port,
uint32_t weight, memcached_connection_t type)
{
- host= memcached_server_create(memc, host);
+ host= _server_create(memc, host);
if (host == NULL)
return NULL;
size_t write_buffer_offset;
struct addrinfo *address_info;
time_t next_retry;
- memcached_st *root;
+ const memcached_st *root;
uint64_t limit_maxbytes;
char read_buffer[MEMCACHED_MAX_BUFFER];
char write_buffer[MEMCACHED_MAX_BUFFER];
/* These should not currently be used by end users */
/* TODO: Is the above comment valid? If so, how can we unit test these if they
* aren't exported. If not, we should remove the comment */
-LIBMEMCACHED_LOCAL
-memcached_server_st *memcached_server_create(memcached_st *memc, memcached_server_st *ptr);
LIBMEMCACHED_LOCAL
-memcached_server_st *memcached_server_create_with(memcached_st *memc,
+memcached_server_st *memcached_server_create_with(const memcached_st *memc,
memcached_server_st *host,
const char *hostname,
in_port_t port,
typedef struct memcached_string_st memcached_string_st;
typedef struct memcached_server_st memcached_server_st;
typedef struct memcached_continuum_item_st memcached_continuum_item_st;
+
typedef memcached_return_t (*memcached_clone_fn)(memcached_st *parent, memcached_st *clone);
-typedef memcached_return_t (*memcached_cleanup_fn)(memcached_st *ptr);
-typedef void (*memcached_free_fn)(memcached_st *ptr, void *mem);
-typedef void *(*memcached_malloc_fn)(memcached_st *ptr, const size_t size);
-typedef void *(*memcached_realloc_fn)(memcached_st *ptr, void *mem, const size_t size);
-typedef void *(*memcached_calloc_fn)(memcached_st *ptr, size_t nelem, const size_t elsize);
-typedef memcached_return_t (*memcached_execute_fn)(memcached_st *ptr, memcached_result_st *result, void *context);
-typedef memcached_return_t (*memcached_server_fn)(memcached_st *ptr, memcached_server_st *server, void *context);
-typedef memcached_return_t (*memcached_trigger_key_fn)(memcached_st *ptr,
+typedef memcached_return_t (*memcached_cleanup_fn)(const memcached_st *ptr);
+
+/**
+ Memory allocation functions.
+*/
+typedef void (*memcached_free_fn)(const memcached_st *ptr, void *mem);
+typedef void *(*memcached_malloc_fn)(const memcached_st *ptr, const size_t size);
+typedef void *(*memcached_realloc_fn)(const memcached_st *ptr, void *mem, const size_t size);
+typedef void *(*memcached_calloc_fn)(const memcached_st *ptr, size_t nelem, const size_t elsize);
+
+typedef memcached_return_t (*memcached_execute_fn)(const memcached_st *ptr, memcached_result_st *result, void *context);
+typedef memcached_return_t (*memcached_server_fn)(const memcached_st *ptr, memcached_server_st *server, void *context);
+
+/**
+ Trigger functions.
+*/
+typedef memcached_return_t (*memcached_trigger_key_fn)(const memcached_st *ptr,
const char *key, size_t key_length,
memcached_result_st *result);
-typedef memcached_return_t (*memcached_trigger_delete_key_fn)(memcached_st *ptr,
+typedef memcached_return_t (*memcached_trigger_delete_key_fn)(const memcached_st *ptr,
const char *key, size_t key_length);
-typedef memcached_return_t (*memcached_dump_fn)(memcached_st *ptr,
+typedef memcached_return_t (*memcached_dump_fn)(const memcached_st *ptr,
const char *key,
size_t key_length,
void *context);
#define TEST_PORT_COUNT 7
in_port_t test_ports[TEST_PORT_COUNT];
-static memcached_return_t server_display_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context)
+static memcached_return_t server_display_function(const memcached_st *ptr __attribute__((unused)),
+ memcached_server_st *server, void *context)
{
/* Do Nothing */
size_t bigger= *((size_t *)(context));
return TEST_SUCCESS;
}
-static memcached_return_t server_display_unsort_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context)
+static memcached_return_t server_display_unsort_function(const memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context)
{
/* Do Nothing */
uint32_t x= *((uint32_t *)(context));
return TEST_SUCCESS;
}
-static memcached_return_t server_function(memcached_st *ptr __attribute__((unused)),
+static memcached_return_t server_function(const memcached_st *ptr __attribute__((unused)),
memcached_server_st *server __attribute__((unused)),
void *context __attribute__((unused)))
{
}
/* Count the results */
-static memcached_return_t callback_counter(memcached_st *ptr __attribute__((unused)),
+static memcached_return_t callback_counter(const memcached_st *ptr __attribute__((unused)),
memcached_result_st *result __attribute__((unused)),
void *context)
{
}
-static void my_free(memcached_st *ptr __attribute__((unused)), void *mem)
+static void my_free(const memcached_st *ptr __attribute__((unused)), void *mem)
{
#ifdef HARD_MALLOC_TESTS
void *real_ptr= (mem == NULL) ? mem : (void*)((caddr_t)mem - 8);
}
-static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size)
+static void *my_malloc(const memcached_st *ptr __attribute__((unused)), const size_t size)
{
#ifdef HARD_MALLOC_TESTS
void *ret= malloc(size + 8);
}
-static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)
+static void *my_realloc(const memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)
{
#ifdef HARD_MALLOC_TESTS
void *real_ptr= (mem == NULL) ? NULL : (void*)((caddr_t)mem - 8);
}
-static void *my_calloc(memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size)
+static void *my_calloc(const memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size)
{
#ifdef HARD_MALLOC_TESTS
void *mem= my_malloc(ptr, nelem * size);
}
/* Count the objects */
-static memcached_return_t callback_dump_counter(memcached_st *ptr __attribute__((unused)),
- const char *key __attribute__((unused)),
- size_t key_length __attribute__((unused)),
- void *context)
+static memcached_return_t callback_dump_counter(const memcached_st *ptr __attribute__((unused)),
+ const char *key __attribute__((unused)),
+ size_t key_length __attribute__((unused)),
+ void *context)
{
size_t *counter= (size_t *)context;
test_return_t mget_result_function(memcached_st *memc);
test_return_t basic_behavior(memcached_st *memc);
test_return_t mget_test(memcached_st *memc);
- memcached_return_t callback_counter(memcached_st *,
+ memcached_return_t callback_counter(const memcached_st *,
memcached_result_st *,
void *context);
}
}
/* Count the results */
-memcached_return_t callback_counter(memcached_st *,
- memcached_result_st *,
- void *context)
+memcached_return_t callback_counter(const memcached_st *,
+ memcached_result_st *,
+ void *context)
{
unsigned int *counter= static_cast<unsigned int *>(context);