Style cleanup
[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/memcached_constants.h>
29 #include <libmemcached/memcached_types.h>
30 #include <libmemcached/memcached_behavior.h>
31 #include <libmemcached/memcached_get.h>
32 #include <libmemcached/memcached_server.h>
33 #include <libmemcached/memcached_string.h>
34 #include <libmemcached/memcached_result.h>
35 #include <libmemcached/memcached_storage.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #define MEMCACHED_VERSION_STRING_LENGTH 24
42
43 struct memcached_analysis_st {
44 uint32_t average_item_size;
45 uint32_t longest_uptime;
46 uint32_t least_free_server;
47 uint32_t most_consumed_server;
48 uint32_t oldest_server;
49 double pool_hit_ratio;
50 uint64_t most_used_bytes;
51 uint64_t least_remaining_bytes;
52 };
53
54 struct memcached_stat_st {
55 uint32_t connection_structures;
56 uint32_t curr_connections;
57 uint32_t curr_items;
58 uint32_t pid;
59 uint32_t pointer_size;
60 uint32_t rusage_system_microseconds;
61 uint32_t rusage_system_seconds;
62 uint32_t rusage_user_microseconds;
63 uint32_t rusage_user_seconds;
64 uint32_t threads;
65 uint32_t time;
66 uint32_t total_connections;
67 uint32_t total_items;
68 uint32_t uptime;
69 uint64_t bytes;
70 uint64_t bytes_read;
71 uint64_t bytes_written;
72 uint64_t cmd_get;
73 uint64_t cmd_set;
74 uint64_t evictions;
75 uint64_t get_hits;
76 uint64_t get_misses;
77 uint64_t limit_maxbytes;
78 char version[MEMCACHED_VERSION_STRING_LENGTH];
79 };
80
81 struct memcached_st {
82 struct {
83 bool is_allocated:1;
84 bool is_initialized:1;
85 bool is_purging:1;
86 } options;
87 uint8_t distribution;
88 uint8_t hash;
89 uint32_t continuum_points_counter;
90 memcached_server_st *hosts;
91 memcached_server_st *last_disconnected_server;
92 int32_t snd_timeout;
93 int32_t rcv_timeout;
94 uint32_t server_failure_limit;
95 uint32_t io_msg_watermark;
96 uint32_t io_bytes_watermark;
97 uint32_t io_key_prefetch;
98 uint32_t number_of_hosts;
99 uint32_t cursor_server;
100 int cached_errno;
101 struct {
102 bool no_block:1;
103 bool tcp_nodelay:1;
104 bool reuse_memory:1;
105 bool use_md5:1;
106 bool use_crc:1;
107 bool use_cache_lookups:1;
108 bool support_cas:1;
109 bool buffer_requests:1;
110 bool use_sort_hosts:1;
111 bool verify_key:1;
112 bool ketama_weighted:1;
113 bool binary_protocol:1;
114 bool hash_with_prefix_key:1;
115 bool no_reply:1;
116 bool use_udp:1;
117 bool auto_eject_hosts:1;
118 bool randomize_replica_read:1;
119 } flags;
120 int32_t poll_timeout;
121 int32_t connect_timeout;
122 int32_t retry_timeout;
123 uint32_t continuum_count;
124 int send_size;
125 int recv_size;
126 void *user_data;
127 time_t next_distribution_rebuild;
128 size_t prefix_key_length;
129 memcached_hash_t hash_continuum;
130 memcached_result_st result;
131 memcached_continuum_item_st *continuum;
132 memcached_clone_fn on_clone;
133 memcached_cleanup_fn on_cleanup;
134 memcached_free_fn call_free;
135 memcached_malloc_fn call_malloc;
136 memcached_realloc_fn call_realloc;
137 memcached_calloc_fn call_calloc;
138 memcached_trigger_key_fn get_key_failure;
139 memcached_trigger_delete_key_fn delete_trigger;
140 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
141 uint32_t number_of_replicas;
142 memcached_callback_st *callbacks;
143 };
144
145 LIBMEMCACHED_API
146 memcached_return_t memcached_version(memcached_st *ptr);
147
148 /* Public API */
149
150 LIBMEMCACHED_API
151 const char * memcached_lib_version(void);
152
153 LIBMEMCACHED_API
154 memcached_st *memcached_create(memcached_st *ptr);
155 LIBMEMCACHED_API
156 void memcached_free(memcached_st *ptr);
157 LIBMEMCACHED_API
158 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
159
160 LIBMEMCACHED_API
161 memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
162 time_t expiration);
163 LIBMEMCACHED_API
164 memcached_return_t memcached_increment(memcached_st *ptr,
165 const char *key, size_t key_length,
166 uint32_t offset,
167 uint64_t *value);
168 LIBMEMCACHED_API
169 memcached_return_t memcached_decrement(memcached_st *ptr,
170 const char *key, size_t key_length,
171 uint32_t offset,
172 uint64_t *value);
173
174 LIBMEMCACHED_API
175 memcached_return_t memcached_increment_by_key(memcached_st *ptr,
176 const char *master_key, size_t master_key_length,
177 const char *key, size_t key_length,
178 uint64_t offset,
179 uint64_t *value);
180
181 LIBMEMCACHED_API
182 memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
183 const char *master_key, size_t master_key_length,
184 const char *key, size_t key_length,
185 uint64_t offset,
186 uint64_t *value);
187
188 LIBMEMCACHED_API
189 memcached_return_t memcached_increment_with_initial(memcached_st *ptr,
190 const char *key,
191 size_t key_length,
192 uint64_t offset,
193 uint64_t initial,
194 time_t expiration,
195 uint64_t *value);
196 LIBMEMCACHED_API
197 memcached_return_t memcached_decrement_with_initial(memcached_st *ptr,
198 const char *key,
199 size_t key_length,
200 uint64_t offset,
201 uint64_t initial,
202 time_t expiration,
203 uint64_t *value);
204 LIBMEMCACHED_API
205 memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr,
206 const char *master_key,
207 size_t master_key_length,
208 const char *key,
209 size_t key_length,
210 uint64_t offset,
211 uint64_t initial,
212 time_t expiration,
213 uint64_t *value);
214 LIBMEMCACHED_API
215 memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr,
216 const char *master_key,
217 size_t master_key_length,
218 const char *key,
219 size_t key_length,
220 uint64_t offset,
221 uint64_t initial,
222 time_t expiration,
223 uint64_t *value);
224 LIBMEMCACHED_API
225 void memcached_stat_free(memcached_st *, memcached_stat_st *);
226
227 LIBMEMCACHED_API
228 memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error);
229
230 LIBMEMCACHED_API
231 memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args,
232 const char *hostname, in_port_t port);
233
234 LIBMEMCACHED_API
235 memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration);
236
237 LIBMEMCACHED_API
238 memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
239
240 LIBMEMCACHED_API
241 void memcached_quit(memcached_st *ptr);
242
243 LIBMEMCACHED_API
244 const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
245
246 /* The two public hash bits */
247 LIBMEMCACHED_API
248 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm);
249
250 LIBMEMCACHED_API
251 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
252
253 LIBMEMCACHED_API
254 memcached_return_t memcached_flush_buffers(memcached_st *mem);
255
256 /* Server Public functions */
257
258 LIBMEMCACHED_API
259 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
260 const char *hostname,
261 in_port_t port);
262 LIBMEMCACHED_API
263 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
264 const char *filename);
265 LIBMEMCACHED_API
266 memcached_return_t memcached_server_add(memcached_st *ptr,
267 const char *hostname, in_port_t port);
268
269 LIBMEMCACHED_API
270 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
271 const char *hostname,
272 in_port_t port,
273 uint32_t weight);
274 LIBMEMCACHED_API
275 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
276 const char *filename,
277 uint32_t weight);
278 LIBMEMCACHED_API
279 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
280 in_port_t port,
281 uint32_t weight);
282 LIBMEMCACHED_API
283 void memcached_server_list_free(memcached_server_st *ptr);
284
285 LIBMEMCACHED_API
286 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
287
288 LIBMEMCACHED_API
289 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
290 const char *hostname,
291 in_port_t port,
292 memcached_return_t *error);
293 LIBMEMCACHED_API
294 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
295 const char *hostname,
296 in_port_t port,
297 uint32_t weight,
298 memcached_return_t *error);
299 LIBMEMCACHED_API
300 unsigned int memcached_server_list_count(memcached_server_st *ptr);
301
302 LIBMEMCACHED_API
303 memcached_server_st *memcached_servers_parse(const char *server_strings);
304
305 LIBMEMCACHED_API
306 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
307 const char *key, memcached_return_t *error);
308 LIBMEMCACHED_API
309 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
310 memcached_return_t *error);
311
312 LIBMEMCACHED_API
313 memcached_return_t memcached_delete_by_key(memcached_st *ptr,
314 const char *master_key, size_t master_key_length,
315 const char *key, size_t key_length,
316 time_t expiration);
317
318 LIBMEMCACHED_API
319 memcached_return_t memcached_fetch_execute(memcached_st *ptr,
320 memcached_execute_fn *callback,
321 void *context,
322 unsigned int number_of_callbacks);
323
324 LIBMEMCACHED_API
325 memcached_return_t memcached_callback_set(memcached_st *ptr,
326 memcached_callback_t flag,
327 void *data);
328 LIBMEMCACHED_API
329 void *memcached_callback_get(memcached_st *ptr,
330 memcached_callback_t flag,
331 memcached_return_t *error);
332
333 LIBMEMCACHED_API
334 memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks);
335
336
337 LIBMEMCACHED_API
338 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
339 memcached_malloc_fn mem_malloc,
340 memcached_free_fn mem_free,
341 memcached_realloc_fn mem_realloc,
342 memcached_calloc_fn mem_calloc);
343
344 LIBMEMCACHED_API
345 void memcached_get_memory_allocators(memcached_st *ptr,
346 memcached_malloc_fn *mem_malloc,
347 memcached_free_fn *mem_free,
348 memcached_realloc_fn *mem_realloc,
349 memcached_calloc_fn *mem_calloc);
350
351 LIBMEMCACHED_API
352 void *memcached_get_user_data(memcached_st *ptr);
353 LIBMEMCACHED_API
354 void *memcached_set_user_data(memcached_st *ptr, void *data);
355
356 LIBMEMCACHED_LOCAL
357 memcached_return_t run_distribution(memcached_st *ptr);
358
359 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
360 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
361
362 #ifdef __cplusplus
363 }
364 #endif
365
366
367 #endif /* __MEMCACHED_H__ */