+0.43
+ * memcached_stat_execute() merged.
+
0.42 Tue Jul 6 12:29:50 PDT 2010
* Mistake in libtool caused issue with library version
typedef struct memcached_server_st * memcached_server_write_instance_st;
+typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);
+
LIBMEMCACHED_LOCAL
memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key);
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_server_execute(memcached_st *ptr,
+ memcached_server_execute_fn callback,
+ void *context);
+
+
/* These are private not to be installed headers */
#include "libmemcached/io.h"
#include "libmemcached/do.h"
return MEMCACHED_SUCCESS;
}
+memcached_return_t memcached_server_execute(memcached_st *ptr,
+ memcached_server_execute_fn callback,
+ void *context)
+{
+ for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
+ {
+ memcached_server_write_instance_st instance=
+ memcached_server_instance_fetch(ptr, x);
+
+ unsigned int iferror;
+
+ iferror= (*callback)(ptr, instance, context);
+
+ if (iferror)
+ continue;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
memcached_server_instance_st memcached_server_by_key(const memcached_st *ptr,
const char *key,
size_t key_length,
NULL
};
+struct local_context
+{
+ memcached_stat_fn func;
+ void *context;
+ const char *args;
+};
+
static memcached_return_t set_data(memcached_stat_st *memc_stat, char *key, char *value)
{
}
static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat,
- char *args,
- memcached_server_write_instance_st instance)
+ const char *args,
+ memcached_server_write_instance_st instance,
+ struct local_context *check)
{
memcached_return_t rc;
return rc;
}
- unlikely((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY)
+ if (memc_stat)
+ {
+ unlikely((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY)
+ {
+ WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
+ WATCHPOINT_ASSERT(0);
+ }
+ }
+
+ if (check && check->func)
{
- WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
- WATCHPOINT_ASSERT(0);
+ size_t key_length= strlen(buffer);
+
+ check->func(instance,
+ buffer, key_length,
+ buffer+key_length+1, strlen(buffer+key_length+1),
+ check->context);
}
} while (1);
}
static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat,
- char *args,
- memcached_server_write_instance_st instance)
+ const char *args,
+ memcached_server_write_instance_st instance,
+ struct local_context *check)
{
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
value= string_ptr;
value[(size_t)(end_ptr-string_ptr)]= 0;
string_ptr= end_ptr + 2;
- unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY)
+ if (memc_stat)
{
- WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
- WATCHPOINT_ASSERT(0);
+ unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY)
+ {
+ WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY);
+ WATCHPOINT_ASSERT(0);
+ }
+ }
+
+ if (check && check->func)
+ {
+ check->func(instance,
+ key, strlen(key),
+ value, strlen(value),
+ check->context);
}
}
else
if (ptr->flags.binary_protocol)
{
- temp_return= binary_stats_fetch(stat_instance, args, instance);
+ temp_return= binary_stats_fetch(stat_instance, args, instance, NULL);
}
else
{
- temp_return= ascii_stats_fetch(stat_instance, args, instance);
+ temp_return= ascii_stats_fetch(stat_instance, args, instance, NULL);
}
if (temp_return != MEMCACHED_SUCCESS)
if (memc.flags.binary_protocol)
{
- rc= binary_stats_fetch(memc_stat, args, instance);
+ rc= binary_stats_fetch(memc_stat, args, instance, NULL);
}
else
{
- rc= ascii_stats_fetch(memc_stat, args, instance);
+ rc= ascii_stats_fetch(memc_stat, args, instance, NULL);
}
memcached_free(&memc);
free(memc_stat);
}
}
+
+static memcached_return_t call_stat_fn(memcached_st *ptr,
+ memcached_server_write_instance_st instance,
+ void *context)
+{
+ memcached_return_t rc;
+ struct local_context *check= (struct local_context *)context;
+
+ if (ptr->flags.binary_protocol)
+ {
+ rc= binary_stats_fetch(NULL, check->args, instance, check);
+ }
+ else
+ {
+ rc= ascii_stats_fetch(NULL, check->args, instance, check);
+ }
+
+ return rc;
+}
+
+memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context)
+{
+ memcached_version(memc);
+
+ struct local_context check= { .func= func, .context= context, .args= args };
+
+ return memcached_server_execute(memc, call_stat_fn, (void *)&check);
+}
char ** memcached_stat_get_keys(const memcached_st *ptr, memcached_stat_st *memc_stat,
memcached_return_t *error);
+LIBMEMCACHED_API
+memcached_return_t memcached_stat_execute(memcached_st *memc, const char *args, memcached_stat_fn func, void *context);
+
#ifdef __cplusplus
} // extern "C"
#endif
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_instance_st server, void *context);
+typedef memcached_return_t (*memcached_stat_fn)(memcached_server_instance_st server,
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
+ void *context);
/**
Trigger functions.
return TEST_SUCCESS;
}
+static memcached_return_t stat_printer(memcached_server_instance_st server,
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
+ void *context)
+{
+ (void)server;
+ (void)context;
+ (void)key;
+ (void)key_length;
+ (void)value;
+ (void)value_length;
+
+ return MEMCACHED_SUCCESS;
+}
+
+static test_return_t memcached_stat_execute_test(memcached_st *memc)
+{
+ memcached_return_t rc= memcached_stat_execute(memc, NULL, stat_printer, NULL);
+ test_true(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_stat_execute(memc, "slabs", stat_printer, NULL);
+ test_true(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_stat_execute(memc, "items", stat_printer, NULL);
+ test_true(rc == MEMCACHED_SUCCESS);
+
+ rc= memcached_stat_execute(memc, "sizes", stat_printer, NULL);
+ test_true(rc == MEMCACHED_SUCCESS);
+
+ return TEST_SUCCESS;
+}
+
/*
* This test ensures that the failure counter isn't incremented during
* normal termination of the memcached instance.
{"verbosity", 1, (test_callback_fn)test_verbosity},
{"test_server_failure", 1, (test_callback_fn)test_server_failure},
{"cull_servers", 1, (test_callback_fn)test_cull_servers},
+ {"memcached_stat_execute", 1, (test_callback_fn)memcached_stat_execute_test},
{0, 0, 0}
};