operations.
+ * Added memcached_callback_get()/set()
* First prototype of C++ interface
* Updated docs for uint16_t changes in previous release
memcached_verbosity.pod\\r
memstat.pod\\r
memcached_behavior.pod\\r
+ memcached_callback.pod\\r
memcached_server_st.pod\\r
memcat.pod\\r
memcached_create.pod\\r
memcached_append_by_key.3\\r
memcached_behavior_get.3\\r
memcached_behavior_set.3\\r
+ memcached_callback_get.3\\r
+ memcached_callback_set.3\\r
memcached_cas.3\\r
memcached_cas_by_key.3\\r
memcached_clone.3\\r
memcached_behavior_set.3: memcached_behavior.pod\r
pod2man -c "libmemcached" -r "" -s 3 memcached_behavior.pod > memcached_behavior_set.3\r
\r
+memcached_callback_get.3: memcached_callback.pod\r
+ pod2man -c "libmemcached" -r "" -s 3 memcached_callback.pod > memcached_callback_get.3\r
+\r
+memcached_callback_set.3: memcached_callback.pod\r
+ pod2man -c "libmemcached" -r "" -s 3 memcached_callback.pod > memcached_callback_set.3\r
+\r
memcached_stat.3: memcached_stats.pod\r
pod2man -c "libmemcached" -r "" -s 3 memcached_stats.pod > memcached_stat.3\r
\r
=head1 SEE ALSO
-memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcahed_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3)
+memcached(1) libmemcached_examples(3) libmemcached(1) memcat(1) memcp(1) memflush(1) memrm(1) memslap(1) memstat(1) memcached_fetch(3) memcached_replace(3) memcached_server_list_free(3) libmemcached_examples(3) memcached_clone(3) memcached_free(3) memcached_server_add(3) memcached_server_push(3) memcached_add(3) memcached_get(3) memcached_server_count(3) memcached_servers_parse(3) memcached_create(3) memcached_increment(3) memcached_server_list(3) memcached_set(3) memcached_decrement(3) memcached_mget(3) memcached_server_list_append(3) memcached_strerror(3) memcached_delete(3) memcached_quit(3) memcached_server_list_count(3) memcached_verbosity(3) memcached_server_add_unix_socket(3) memcahed_result_create(3) memcached_result_free(3) memcached_result_key_value(3) memcached_result_key_length(3) memcached_result_value(3) memcached_result_length(3) memcached_result_flags(3) memcached_result_cas(3) memcached_result_st(3) memcached_append(3) memcached_prepend(3) memcached_fetch_result(3) memerror(1) memcached_get_by_key(3) memcached_mget_by_key(3) memcached_delete_by_key(3) memcached_fetch_execute(3) memcached_callback_get(3) memcached_callback_set(3)
=cut
This allows you to store a pointer to a specifc piece of data. This can be
retrieved from inside of memcached_fetch_exectue(). Cloning a memcached_st
-will copy the pointer to the clone.
+will copy the pointer to the clone. This was deprecated in 0.14 in favor
+of memcached_callback_set(3). This will be removed in 0.15.
=item MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
extern "C" {
#endif
-typedef struct memcached_st memcached_st;
-typedef struct memcached_stat_st memcached_stat_st;
-typedef struct memcached_result_st memcached_result_st;
-typedef struct memcached_string_st memcached_string_st;
-typedef struct memcached_server_st memcached_server_st;
-
/* These are Private and should not be used by applications */
#define MEMCACHED_VERSION_STRING_LENGTH 12
MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */
} memcached_return;
+typedef struct memcached_st memcached_st;
+typedef struct memcached_stat_st memcached_stat_st;
+typedef struct memcached_result_st memcached_result_st;
+typedef struct memcached_string_st memcached_string_st;
+typedef struct memcached_server_st memcached_server_st;
+typedef memcached_return (*clone_func)(memcached_st *parent, memcached_st *clone);
+typedef memcached_return (*cleanup_func)(memcached_st *ptr);
+
+
typedef enum {
MEMCACHED_DISTRIBUTION_MODULA,
MEMCACHED_DISTRIBUTION_CONSISTENT,
MEMCACHED_BEHAVIOR_USER_DATA,
} memcached_behavior;
+typedef enum {
+ MEMCACHED_CALLBACK_USER_DATA,
+ MEMCACHED_CALLBACK_CLEANUP_FUNCTION,
+ MEMCACHED_CALLBACK_CLONE_FUNCTION,
+} memcached_callback;
+
typedef enum {
MEMCACHED_HASH_DEFAULT= 0,
MEMCACHED_HASH_MD5,
memcached_server_distribution distribution;
void *user_data;
unsigned int wheel[MEMCACHED_WHEEL_SIZE];
+ clone_func on_clone;
+ cleanup_func on_cleanup;
#ifdef NOT_USED /* Future Use */
uint8_t replicas;
memcached_return warning;
unsigned int number_of_callbacks
);
+memcached_return memcached_callback_set(memcached_st *ptr,
+ memcached_callback flag,
+ void *data);
+void *memcached_callback_get(memcached_st *ptr,
+ memcached_callback flag,
+ memcached_return *error);
+
/* Result Struct */
void memcached_result_free(memcached_result_st *result);
memcached_result_st *memcached_result_create(memcached_st *ptr,
memcached.c \
memcached_auto.c \
memcached_behavior.c \
+ memcached_callback.c \
memcached_connect.c \
memcached_delete.c \
memcached_do.c \
temp_flag= MEM_USE_KETAMA;
break;
case MEMCACHED_BEHAVIOR_USER_DATA:
- return (unsigned long long)ptr->user_data;
+ return 0;
+ //return (unsigned long long)ptr->user_data;
case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
{
return (unsigned long long)ptr->poll_timeout;
--- /dev/null
+#include "common.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+
+/*
+ These functions provide data and function callback support
+*/
+
+memcached_return memcached_callback_set(memcached_st *ptr,
+ memcached_callback flag,
+ void *data)
+{
+ switch (flag)
+ {
+ case MEMCACHED_CALLBACK_USER_DATA:
+ {
+ ptr->user_data= data;
+ break;
+ }
+ case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
+ {
+ cleanup_func func= (cleanup_func)data;
+ ptr->on_cleanup= func;
+ break;
+ }
+ case MEMCACHED_CALLBACK_CLONE_FUNCTION:
+ {
+ clone_func func= (clone_func)data;
+ ptr->on_clone= func;
+ break;
+ }
+ default:
+ return MEMCACHED_FAILURE;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
+void *memcached_callback_get(memcached_st *ptr,
+ memcached_callback flag,
+ memcached_return *error)
+{
+ switch (flag)
+ {
+ case MEMCACHED_CALLBACK_USER_DATA:
+ {
+ *error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
+ return (void *)ptr->user_data;
+ }
+ case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
+ {
+ *error= ptr->on_cleanup ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
+ return (void *)ptr->on_cleanup;
+ }
+ case MEMCACHED_CALLBACK_CLONE_FUNCTION:
+ {
+ *error= ptr->on_clone ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
+ return (void *)ptr->on_clone;
+ }
+ default:
+ WATCHPOINT_ASSERT(0);
+ *error= MEMCACHED_FAILURE;
+ return NULL;
+ }
+}
%{_mandir}/man3/memcached_behavior_set.3.gz
%{_mandir}/man3/memcached_cas.3.gz
%{_mandir}/man3/memcached_cas_by_key.3.gz
+%{_mandir}/man3/memcached_callback_get.3.gz
+%{_mandir}/man3/memcached_callback_set.3.gz
%{_mandir}/man3/memcached_clone.3.gz
%{_mandir}/man3/memcached_create.3.gz
%{_mandir}/man3/memcached_decrement.3.gz
return 0;
}
+memcached_return clone_test_callback(memcached_st *parent, memcached_st *clone)
+{
+ return MEMCACHED_SUCCESS;
+}
+
+memcached_return cleanup_test_callback(memcached_st *ptr)
+{
+ return MEMCACHED_SUCCESS;
+}
+
+uint8_t callback_test(memcached_st *memc)
+{
+ /* Test User Data */
+ {
+ int x= 5;
+ int *test_ptr;
+ memcached_return rc;
+
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x);
+ assert(rc == MEMCACHED_SUCCESS);
+ test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
+ assert(*test_ptr == x);
+ }
+
+ /* Test Clone Callback */
+ {
+ clone_func temp_function;
+ memcached_return rc;
+
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, clone_test_callback);
+ assert(rc == MEMCACHED_SUCCESS);
+ temp_function= (clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
+ assert(temp_function == clone_test_callback);
+ }
+
+ /* Test Cleanup Callback */
+ {
+ cleanup_func temp_function;
+ memcached_return rc;
+
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, cleanup_test_callback);
+ assert(rc == MEMCACHED_SUCCESS);
+ temp_function= (cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
+ assert(temp_function == cleanup_test_callback);
+ }
+
+ return 0;
+}
+
/* We don't test the behavior itself, we test the switches */
uint8_t behavior_test(memcached_st *memc)
{
{"add_host_test", 0, add_host_test },
{"get_stats_keys", 0, get_stats_keys },
{"behavior_test", 0, get_stats_keys },
+ {"callback_test", 0, get_stats_keys },
{0, 0, 0}
};