From: Brian Aker Date: Sat, 16 Jan 2010 00:59:13 +0000 (-0800) Subject: File Refactoring X-Git-Tag: 0.40~94 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8f36e509f6130022162abf7cde7e6c8acbbe224c;p=m6w6%2Flibmemcached File Refactoring --- diff --git a/libmemcached/allocators.h b/libmemcached/allocators.h new file mode 100644 index 00000000..d22bc652 --- /dev/null +++ b/libmemcached/allocators.h @@ -0,0 +1,38 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: work with user defined memory allocators + * + */ + +#ifndef __MEMCACHED_ALLOCATORS_H__ +#define __MEMCACHED_ALLOCATORS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_set_memory_allocators(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, + memcached_malloc_fn *mem_malloc, + memcached_free_fn *mem_free, + memcached_realloc_fn *mem_realloc, + memcached_calloc_fn *mem_calloc); + + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_ALLOCATORS_H__ */ diff --git a/libmemcached/common.h b/libmemcached/common.h index 895c5a40..18dc349a 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -116,10 +116,24 @@ memcached_return_t memcached_connect(memcached_server_instance_st *ptr); LIBMEMCACHED_LOCAL void memcached_quit_server(memcached_server_instance_st *ptr, uint8_t io_death); +LIBMEMCACHED_LOCAL +memcached_return_t run_distribution(memcached_st *ptr); + #define memcached_server_response_increment(A) (A)->cursor_active++ #define memcached_server_response_decrement(A) (A)->cursor_active-- #define memcached_server_response_reset(A) (A)->cursor_active=0 +// These are private +#define memcached_is_allocated(__object) ((__object)->options.is_allocated) +#define memcached_is_initialized(__object) ((__object)->options.is_initialized) +#define memcached_is_purging(__object) ((__object)->flags.is_purging) +#define memcached_is_processing_input(__object) ((__object)->flags.is_processing_input) +#define memcached_set_purging(__object, __value) ((__object)->flags.is_purging= (__value)) +#define memcached_set_processing_input(__object, __value) ((__object)->flags.is_processing_input= (__value)) +#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) +#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value)) + + LIBMEMCACHED_LOCAL memcached_return_t memcached_do(memcached_server_instance_st *ptr, const void *commmand, size_t command_length, uint8_t with_flush); diff --git a/libmemcached/delete.h b/libmemcached/delete.h new file mode 100644 index 00000000..1992ac36 --- /dev/null +++ b/libmemcached/delete.h @@ -0,0 +1,33 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Delete a key from the server. + * + */ + +#ifndef __MEMCACHED_DELETE_H__ +#define __MEMCACHED_DELETE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length, + time_t expiration); + +LIBMEMCACHED_API +memcached_return_t memcached_delete_by_key(memcached_st *ptr, + const char *master_key, size_t master_key_length, + const char *key, size_t key_length, + time_t expiration); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_DELETE_H__ */ diff --git a/libmemcached/fetch.h b/libmemcached/fetch.h new file mode 100644 index 00000000..cd12d384 --- /dev/null +++ b/libmemcached/fetch.h @@ -0,0 +1,29 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Work with fetching results + * + */ + +#ifndef __MEMCACHED_FETCH_H__ +#define __MEMCACHED_FETCH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_fetch_execute(memcached_st *ptr, + memcached_execute_fn *callback, + void *context, + uint32_t number_of_callbacks); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_FETCH_H__ */ diff --git a/libmemcached/flush.h b/libmemcached/flush.h new file mode 100644 index 00000000..dd2f5aef --- /dev/null +++ b/libmemcached/flush.h @@ -0,0 +1,26 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Flush connections. + * + */ + +#ifndef __MEMCACHED_FLUSH_H__ +#define __MEMCACHED_FLUSH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_FLUSH_H__ */ diff --git a/libmemcached/flush_buffers.h b/libmemcached/flush_buffers.h new file mode 100644 index 00000000..a7d1e19a --- /dev/null +++ b/libmemcached/flush_buffers.h @@ -0,0 +1,26 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Work with fetching results + * + */ + +#ifndef __MEMCACHED_FLUSH_BUFFERS_H__ +#define __MEMCACHED_FLUSH_BUFFERS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_flush_buffers(memcached_st *mem); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_FLUSH_BUFFERS_H__ */ diff --git a/libmemcached/hash.h b/libmemcached/hash.h new file mode 100644 index 00000000..d82372d8 --- /dev/null +++ b/libmemcached/hash.h @@ -0,0 +1,30 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: hash interface code + * + */ + +#ifndef __MEMCACHED_HASH_H__ +#define __MEMCACHED_HASH_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* The two public hash bits */ +LIBMEMCACHED_API +uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm); + +LIBMEMCACHED_API +uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_HASH_H__ */ diff --git a/libmemcached/include.am b/libmemcached/include.am index 41c5c597..d8549d69 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -19,27 +19,38 @@ noinst_HEADERS+= \ libmemcached/response.h nobase_include_HEADERS+= \ + libmemcached/allocators.h \ libmemcached/analyze.h \ libmemcached/auto.h \ libmemcached/behavior.h \ libmemcached/callback.h \ libmemcached/configure.h \ libmemcached/constants.h \ + libmemcached/delete.h \ libmemcached/dump.h \ libmemcached/exception.hpp \ + libmemcached/fetch.h \ + libmemcached/flush.h \ + libmemcached/flush_buffers.h \ libmemcached/get.h \ + libmemcached/hash.h \ libmemcached/memcached.h \ libmemcached/memcached.hpp \ libmemcached/memcached/protocol_binary.h \ + libmemcached/parse.h \ libmemcached/protocol/cache.h \ libmemcached/protocol/callback.h \ libmemcached/protocol_handler.h \ + libmemcached/quit.h \ libmemcached/result.h \ libmemcached/server.h \ libmemcached/stats.h \ libmemcached/storage.h \ + libmemcached/strerror.h \ libmemcached/string.h \ libmemcached/types.h \ + libmemcached/verbosity.h \ + libmemcached/version.h \ libmemcached/visibility.h \ libmemcached/watchpoint.h diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 2b96d422..c2fbfa8d 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -189,7 +189,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) return new_clone; } -void *memcached_get_user_data(memcached_st *ptr) +void *memcached_get_user_data(const memcached_st *ptr) { return ptr->user_data; } diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 52ed0c22..2a7dd3f0 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -30,15 +30,26 @@ #include #include // Everything above this line must be in the order specified. +#include #include #include #include #include +#include #include +#include +#include +#include #include +#include +#include +#include #include #include #include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -110,155 +121,32 @@ struct memcached_st { } options; }; -LIBMEMCACHED_API -memcached_return_t memcached_version(memcached_st *ptr); - LIBMEMCACHED_API void memcached_servers_reset(memcached_st *ptr); -// Local Only Inline -static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) -{ - return &ptr->servers[server_key]; -} - /* Public API */ -LIBMEMCACHED_API -const char * memcached_lib_version(void); - LIBMEMCACHED_API memcached_st *memcached_create(memcached_st *ptr); -LIBMEMCACHED_API -void memcached_free(memcached_st *ptr); -LIBMEMCACHED_API -memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr); - -LIBMEMCACHED_API -memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length, - time_t expiration); - -LIBMEMCACHED_API -memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration); - -LIBMEMCACHED_API -memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity); - -LIBMEMCACHED_API -void memcached_quit(memcached_st *ptr); - -LIBMEMCACHED_API -const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc); - -/* The two public hash bits */ -LIBMEMCACHED_API -uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm); - -LIBMEMCACHED_API -uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length); - -LIBMEMCACHED_API -memcached_return_t memcached_flush_buffers(memcached_st *mem); - -/* Server Public functions */ LIBMEMCACHED_API -memcached_return_t memcached_server_add_udp(memcached_st *ptr, - const char *hostname, - in_port_t port); -LIBMEMCACHED_API -memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, - const char *filename); -LIBMEMCACHED_API -memcached_return_t memcached_server_add(memcached_st *ptr, - const char *hostname, in_port_t port); - -LIBMEMCACHED_API -memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, - const char *hostname, - in_port_t port, - uint32_t weight); -LIBMEMCACHED_API -memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr, - const char *filename, - uint32_t weight); -LIBMEMCACHED_API -memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname, - in_port_t port, - uint32_t weight); -LIBMEMCACHED_API -void memcached_server_list_free(memcached_server_st *ptr); - -LIBMEMCACHED_API -memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list); - -LIBMEMCACHED_API -memcached_server_st *memcached_server_list_append(memcached_server_st *ptr, - const char *hostname, - in_port_t port, - memcached_return_t *error); -LIBMEMCACHED_API -memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr, - const char *hostname, - in_port_t port, - uint32_t weight, - memcached_return_t *error); -LIBMEMCACHED_API -unsigned int memcached_server_list_count(memcached_server_st *ptr); - -LIBMEMCACHED_API -memcached_server_st *memcached_servers_parse(const char *server_strings); - -LIBMEMCACHED_API -char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, - const char *key, memcached_return_t *error); -LIBMEMCACHED_API -char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat, - memcached_return_t *error); - -LIBMEMCACHED_API -memcached_return_t memcached_delete_by_key(memcached_st *ptr, - const char *master_key, size_t master_key_length, - const char *key, size_t key_length, - time_t expiration); - -LIBMEMCACHED_API -memcached_return_t memcached_fetch_execute(memcached_st *ptr, - memcached_execute_fn *callback, - void *context, - unsigned int number_of_callbacks); +void memcached_free(memcached_st *ptr); LIBMEMCACHED_API -memcached_return_t memcached_set_memory_allocators(memcached_st *ptr, - memcached_malloc_fn mem_malloc, - memcached_free_fn mem_free, - memcached_realloc_fn mem_realloc, - memcached_calloc_fn mem_calloc); +memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr); LIBMEMCACHED_API -void memcached_get_memory_allocators(memcached_st *ptr, - memcached_malloc_fn *mem_malloc, - memcached_free_fn *mem_free, - memcached_realloc_fn *mem_realloc, - memcached_calloc_fn *mem_calloc); +void *memcached_get_user_data(const memcached_st *ptr); -LIBMEMCACHED_API -void *memcached_get_user_data(memcached_st *ptr); LIBMEMCACHED_API void *memcached_set_user_data(memcached_st *ptr, void *data); -LIBMEMCACHED_LOCAL -memcached_return_t run_distribution(memcached_st *ptr); +// Local Only Inline +static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) +{ + return &ptr->servers[server_key]; +} -// These are private -#define memcached_is_allocated(__object) ((__object)->options.is_allocated) -#define memcached_is_initialized(__object) ((__object)->options.is_initialized) -#define memcached_is_purging(__object) ((__object)->flags.is_purging) -#define memcached_is_processing_input(__object) ((__object)->flags.is_processing_input) -#define memcached_set_purging(__object, __value) ((__object)->flags.is_purging= (__value)) -#define memcached_set_processing_input(__object, __value) ((__object)->flags.is_processing_input= (__value)) -#define memcached_set_initialized(__object, __value) ((__object)->options.is_initialized(= (__value)) -#define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value)) #ifdef __cplusplus } diff --git a/libmemcached/parse.h b/libmemcached/parse.h new file mode 100644 index 00000000..d3a08f1a --- /dev/null +++ b/libmemcached/parse.h @@ -0,0 +1,26 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Work with fetching results + * + */ + +#ifndef __MEMCACHED_PARSE_H__ +#define __MEMCACHED_PARSE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_server_st *memcached_servers_parse(const char *server_strings); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_PARSE_H__ */ diff --git a/libmemcached/quit.h b/libmemcached/quit.h new file mode 100644 index 00000000..7b98427f --- /dev/null +++ b/libmemcached/quit.h @@ -0,0 +1,26 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: returns a human readable string for the error message + * + */ + +#ifndef __MEMCACHED_QUIT_H__ +#define __MEMCACHED_QUIT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +void memcached_quit(memcached_st *ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_QUIT_H__ */ diff --git a/libmemcached/server.h b/libmemcached/server.h index 0051e061..1a92eea7 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -116,6 +116,55 @@ memcached_return_t memcached_server_remove(memcached_server_st *st_ptr); LIBMEMCACHED_API memcached_server_st *memcached_server_get_last_disconnect(memcached_st *ptr); + +LIBMEMCACHED_API +memcached_return_t memcached_server_add_udp(memcached_st *ptr, + const char *hostname, + in_port_t port); +LIBMEMCACHED_API +memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, + const char *filename); +LIBMEMCACHED_API +memcached_return_t memcached_server_add(memcached_st *ptr, + const char *hostname, in_port_t port); + +LIBMEMCACHED_API +memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, + const char *hostname, + in_port_t port, + uint32_t weight); +LIBMEMCACHED_API +memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr, + const char *filename, + uint32_t weight); +LIBMEMCACHED_API +memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname, + in_port_t port, + uint32_t weight); +/* Server List Public functions */ + +LIBMEMCACHED_API +void memcached_server_list_free(memcached_server_st *ptr); + + +LIBMEMCACHED_API +memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list); + +LIBMEMCACHED_API +memcached_server_st *memcached_server_list_append(memcached_server_st *ptr, + const char *hostname, + in_port_t port, + memcached_return_t *error); +LIBMEMCACHED_API +memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr, + const char *hostname, + in_port_t port, + uint32_t weight, + memcached_return_t *error); +LIBMEMCACHED_API +unsigned int memcached_server_list_count(memcached_server_st *ptr); + + #ifdef __cplusplus } #endif diff --git a/libmemcached/stats.h b/libmemcached/stats.h index 4b7d48ca..c7d554b2 100644 --- a/libmemcached/stats.h +++ b/libmemcached/stats.h @@ -54,6 +54,14 @@ LIBMEMCACHED_API memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args, const char *hostname, in_port_t port); +LIBMEMCACHED_API +char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, + const char *key, memcached_return_t *error); + +LIBMEMCACHED_API +char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat, + memcached_return_t *error); + #ifdef __cplusplus } #endif diff --git a/libmemcached/strerror.h b/libmemcached/strerror.h new file mode 100644 index 00000000..064b6460 --- /dev/null +++ b/libmemcached/strerror.h @@ -0,0 +1,26 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: returns a human readable string for the error message + * + */ + +#ifndef __MEMCACHED_STRERROR_H__ +#define __MEMCACHED_STRERROR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_STRERROR_H__ */ diff --git a/libmemcached/verbosity.c b/libmemcached/verbosity.c index 90a16f7e..7c7b7ae1 100644 --- a/libmemcached/verbosity.c +++ b/libmemcached/verbosity.c @@ -1,6 +1,6 @@ #include "common.h" -memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity) +memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity) { uint32_t x; size_t send_length; diff --git a/libmemcached/verbosity.h b/libmemcached/verbosity.h new file mode 100644 index 00000000..172ab9f6 --- /dev/null +++ b/libmemcached/verbosity.h @@ -0,0 +1,27 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Change the verbository level of the memcached server + * + */ + +#ifndef __MEMCACHED_VERBOSITY_H__ +#define __MEMCACHED_VERBOSITY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity); + + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_VERBOSITY_H__ */ diff --git a/libmemcached/version.h b/libmemcached/version.h new file mode 100644 index 00000000..8df9f0ac --- /dev/null +++ b/libmemcached/version.h @@ -0,0 +1,29 @@ +/* LibMemcached + * Copyright (C) 2010 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Find version information + * + */ + +#ifndef __MEMCACHED_VERSION_H__ +#define __MEMCACHED_VERSION_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_API +memcached_return_t memcached_version(memcached_st *ptr); + +LIBMEMCACHED_API +const char * memcached_lib_version(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __MEMCACHED_VERSION_H__ */ diff --git a/support/libmemcached.spec.in b/support/libmemcached.spec.in index ea4817aa..7b518e10 100644 --- a/support/libmemcached.spec.in +++ b/support/libmemcached.spec.in @@ -100,6 +100,17 @@ you will need to install %{name}-devel. %files devel %defattr (-,root,root,-) %doc examples +%{_includedir}/libmemcached/allocators.h +%{_includedir}/libmemcached/delete.h +%{_includedir}/libmemcached/fetch.h +%{_includedir}/libmemcached/flush.h +%{_includedir}/libmemcached/flush_buffers.h +%{_includedir}/libmemcached/hash.h +%{_includedir}/libmemcached/parse.h +%{_includedir}/libmemcached/quit.h +%{_includedir}/libmemcached/strerror.h +%{_includedir}/libmemcached/verbosity.h +%{_includedir}/libmemcached/version.h %{_includedir}/libhashkit/algorithm.h %{_includedir}/libhashkit/behavior.h %{_includedir}/libhashkit/hashkit.h