ICC fixes.
[awesomized/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 // Everything above this line must be in the order specified.
32 #include <libmemcached/behavior.h>
33 #include <libmemcached/callback.h>
34 #include <libmemcached/get.h>
35 #include <libmemcached/result.h>
36 #include <libmemcached/server.h>
37 #include <libmemcached/storage.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #define MEMCACHED_VERSION_STRING_LENGTH 24
44
45 struct memcached_analysis_st {
46 uint32_t average_item_size;
47 uint32_t longest_uptime;
48 uint32_t least_free_server;
49 uint32_t most_consumed_server;
50 uint32_t oldest_server;
51 double pool_hit_ratio;
52 uint64_t most_used_bytes;
53 uint64_t least_remaining_bytes;
54 };
55
56 struct memcached_stat_st {
57 uint32_t connection_structures;
58 uint32_t curr_connections;
59 uint32_t curr_items;
60 uint32_t pid;
61 uint32_t pointer_size;
62 uint32_t rusage_system_microseconds;
63 uint32_t rusage_system_seconds;
64 uint32_t rusage_user_microseconds;
65 uint32_t rusage_user_seconds;
66 uint32_t threads;
67 uint32_t time;
68 uint32_t total_connections;
69 uint32_t total_items;
70 uint32_t uptime;
71 uint64_t bytes;
72 uint64_t bytes_read;
73 uint64_t bytes_written;
74 uint64_t cmd_get;
75 uint64_t cmd_set;
76 uint64_t evictions;
77 uint64_t get_hits;
78 uint64_t get_misses;
79 uint64_t limit_maxbytes;
80 char version[MEMCACHED_VERSION_STRING_LENGTH];
81 };
82
83 struct memcached_st {
84 struct {
85 bool is_allocated:1;
86 bool is_initialized:1;
87 bool is_purging:1;
88 } options;
89 memcached_server_distribution_t distribution;
90 memcached_hash_t hash;
91 uint32_t continuum_points_counter;
92 memcached_server_st *hosts;
93 memcached_server_st *last_disconnected_server;
94 int32_t snd_timeout;
95 int32_t rcv_timeout;
96 uint32_t server_failure_limit;
97 uint32_t io_msg_watermark;
98 uint32_t io_bytes_watermark;
99 uint32_t io_key_prefetch;
100 uint32_t number_of_hosts;
101 uint32_t cursor_server;
102 int cached_errno;
103 struct {
104 bool auto_eject_hosts:1;
105 bool binary_protocol:1;
106 bool buffer_requests:1;
107 bool hash_with_prefix_key:1;
108 bool ketama_weighted:1;
109 bool no_block:1;
110 bool no_reply:1;
111 bool randomize_replica_read:1;
112 bool reuse_memory:1;
113 bool support_cas:1;
114 bool tcp_nodelay:1;
115 bool use_cache_lookups:1;
116 bool use_sort_hosts:1;
117 bool use_udp:1;
118 bool verify_key: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 distribution_hash;
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_dump(memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks);
326
327
328 LIBMEMCACHED_API
329 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
330 memcached_malloc_fn mem_malloc,
331 memcached_free_fn mem_free,
332 memcached_realloc_fn mem_realloc,
333 memcached_calloc_fn mem_calloc);
334
335 LIBMEMCACHED_API
336 void memcached_get_memory_allocators(memcached_st *ptr,
337 memcached_malloc_fn *mem_malloc,
338 memcached_free_fn *mem_free,
339 memcached_realloc_fn *mem_realloc,
340 memcached_calloc_fn *mem_calloc);
341
342 LIBMEMCACHED_API
343 void *memcached_get_user_data(memcached_st *ptr);
344 LIBMEMCACHED_API
345 void *memcached_set_user_data(memcached_st *ptr, void *data);
346
347 LIBMEMCACHED_LOCAL
348 memcached_return_t run_distribution(memcached_st *ptr);
349
350 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
351 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
352
353 #ifdef __cplusplus
354 }
355 #endif
356
357
358 #endif /* __MEMCACHED_H__ */