Made the memcached_string stuff private, but still testable.
[m6w6/libmemcached] / libmemcached / memcached.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: interface for memcached server
9 * Description: main include file for libmemcached
10 *
11 */
12
13 #ifndef __MEMCACHED_H__
14 #define __MEMCACHED_H__
15
16 #include <stdlib.h>
17 #include <inttypes.h>
18
19 #if !defined(__cplusplus)
20 # include <stdbool.h>
21 #endif
22
23 #include <sys/types.h>
24 #include <netinet/in.h>
25
26 #include <libmemcached/visibility.h>
27 #include <libmemcached/memcached_configure.h>
28 #include <libmemcached/constants.h>
29 #include <libmemcached/types.h>
30 #include <libmemcached/string.h>
31 #include <libmemcached/stats.h>
32 // Everything above this line must be in the order specified.
33 #include <libmemcached/analyze.h>
34 #include <libmemcached/auto.h>
35 #include <libmemcached/behavior.h>
36 #include <libmemcached/callback.h>
37 #include <libmemcached/dump.h>
38 #include <libmemcached/get.h>
39 #include <libmemcached/result.h>
40 #include <libmemcached/server.h>
41 #include <libmemcached/storage.h>
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 struct memcached_st {
48 struct {
49 bool is_allocated:1;
50 bool is_initialized:1;
51 bool is_purging:1;
52 } options;
53 memcached_server_distribution_t distribution;
54 memcached_hash_t hash;
55 uint32_t continuum_points_counter;
56 memcached_server_st *hosts;
57 memcached_server_st *last_disconnected_server;
58 int32_t snd_timeout;
59 int32_t rcv_timeout;
60 uint32_t server_failure_limit;
61 uint32_t io_msg_watermark;
62 uint32_t io_bytes_watermark;
63 uint32_t io_key_prefetch;
64 uint32_t number_of_hosts;
65 uint32_t cursor_server;
66 int cached_errno;
67 struct {
68 bool auto_eject_hosts:1;
69 bool binary_protocol:1;
70 bool buffer_requests:1;
71 bool hash_with_prefix_key:1;
72 bool ketama_weighted:1;
73 bool no_block:1;
74 bool no_reply:1;
75 bool randomize_replica_read:1;
76 bool reuse_memory:1;
77 bool support_cas:1;
78 bool tcp_nodelay:1;
79 bool use_cache_lookups:1;
80 bool use_sort_hosts:1;
81 bool use_udp:1;
82 bool verify_key:1;
83 } flags;
84 int32_t poll_timeout;
85 int32_t connect_timeout;
86 int32_t retry_timeout;
87 uint32_t continuum_count;
88 int send_size;
89 int recv_size;
90 void *user_data;
91 time_t next_distribution_rebuild;
92 size_t prefix_key_length;
93 uint32_t number_of_replicas;
94 memcached_hash_t distribution_hash;
95 memcached_result_st result;
96 memcached_continuum_item_st *continuum;
97 memcached_clone_fn on_clone;
98 memcached_cleanup_fn on_cleanup;
99 memcached_free_fn call_free;
100 memcached_malloc_fn call_malloc;
101 memcached_realloc_fn call_realloc;
102 memcached_calloc_fn call_calloc;
103 memcached_trigger_key_fn get_key_failure;
104 memcached_trigger_delete_key_fn delete_trigger;
105 memcached_callback_st *callbacks;
106 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
107 };
108
109 LIBMEMCACHED_API
110 memcached_return_t memcached_version(memcached_st *ptr);
111
112 /* Public API */
113
114 LIBMEMCACHED_API
115 const char * memcached_lib_version(void);
116
117 LIBMEMCACHED_API
118 memcached_st *memcached_create(memcached_st *ptr);
119 LIBMEMCACHED_API
120 void memcached_free(memcached_st *ptr);
121 LIBMEMCACHED_API
122 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
123
124 LIBMEMCACHED_API
125 memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
126 time_t expiration);
127
128 LIBMEMCACHED_API
129 memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration);
130
131 LIBMEMCACHED_API
132 memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
133
134 LIBMEMCACHED_API
135 void memcached_quit(memcached_st *ptr);
136
137 LIBMEMCACHED_API
138 const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
139
140 /* The two public hash bits */
141 LIBMEMCACHED_API
142 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm);
143
144 LIBMEMCACHED_API
145 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
146
147 LIBMEMCACHED_API
148 memcached_return_t memcached_flush_buffers(memcached_st *mem);
149
150 /* Server Public functions */
151
152 LIBMEMCACHED_API
153 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
154 const char *hostname,
155 in_port_t port);
156 LIBMEMCACHED_API
157 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
158 const char *filename);
159 LIBMEMCACHED_API
160 memcached_return_t memcached_server_add(memcached_st *ptr,
161 const char *hostname, in_port_t port);
162
163 LIBMEMCACHED_API
164 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
165 const char *hostname,
166 in_port_t port,
167 uint32_t weight);
168 LIBMEMCACHED_API
169 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
170 const char *filename,
171 uint32_t weight);
172 LIBMEMCACHED_API
173 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
174 in_port_t port,
175 uint32_t weight);
176 LIBMEMCACHED_API
177 void memcached_server_list_free(memcached_server_st *ptr);
178
179 LIBMEMCACHED_API
180 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
181
182 LIBMEMCACHED_API
183 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
184 const char *hostname,
185 in_port_t port,
186 memcached_return_t *error);
187 LIBMEMCACHED_API
188 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
189 const char *hostname,
190 in_port_t port,
191 uint32_t weight,
192 memcached_return_t *error);
193 LIBMEMCACHED_API
194 unsigned int memcached_server_list_count(memcached_server_st *ptr);
195
196 LIBMEMCACHED_API
197 memcached_server_st *memcached_servers_parse(const char *server_strings);
198
199 LIBMEMCACHED_API
200 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
201 const char *key, memcached_return_t *error);
202 LIBMEMCACHED_API
203 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
204 memcached_return_t *error);
205
206 LIBMEMCACHED_API
207 memcached_return_t memcached_delete_by_key(memcached_st *ptr,
208 const char *master_key, size_t master_key_length,
209 const char *key, size_t key_length,
210 time_t expiration);
211
212 LIBMEMCACHED_API
213 memcached_return_t memcached_fetch_execute(memcached_st *ptr,
214 memcached_execute_fn *callback,
215 void *context,
216 unsigned int number_of_callbacks);
217
218 LIBMEMCACHED_API
219 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
220 memcached_malloc_fn mem_malloc,
221 memcached_free_fn mem_free,
222 memcached_realloc_fn mem_realloc,
223 memcached_calloc_fn mem_calloc);
224
225 LIBMEMCACHED_API
226 void memcached_get_memory_allocators(memcached_st *ptr,
227 memcached_malloc_fn *mem_malloc,
228 memcached_free_fn *mem_free,
229 memcached_realloc_fn *mem_realloc,
230 memcached_calloc_fn *mem_calloc);
231
232 LIBMEMCACHED_API
233 void *memcached_get_user_data(memcached_st *ptr);
234 LIBMEMCACHED_API
235 void *memcached_set_user_data(memcached_st *ptr, void *data);
236
237 LIBMEMCACHED_LOCAL
238 memcached_return_t run_distribution(memcached_st *ptr);
239
240 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
241 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247
248 #endif /* __MEMCACHED_H__ */