Fix for solaris.
[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 // 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 no_block:1;
105 bool tcp_nodelay:1;
106 bool reuse_memory:1;
107 bool use_md5:1;
108 bool use_crc:1;
109 bool use_cache_lookups:1;
110 bool support_cas:1;
111 bool buffer_requests:1;
112 bool use_sort_hosts:1;
113 bool verify_key:1;
114 bool ketama_weighted:1;
115 bool binary_protocol:1;
116 bool hash_with_prefix_key:1;
117 bool no_reply:1;
118 bool use_udp:1;
119 bool auto_eject_hosts:1;
120 bool randomize_replica_read:1;
121 } flags;
122 int32_t poll_timeout;
123 int32_t connect_timeout;
124 int32_t retry_timeout;
125 uint32_t continuum_count;
126 int send_size;
127 int recv_size;
128 void *user_data;
129 time_t next_distribution_rebuild;
130 size_t prefix_key_length;
131 memcached_hash_t distribution_hash;
132 memcached_result_st result;
133 memcached_continuum_item_st *continuum;
134 memcached_clone_fn on_clone;
135 memcached_cleanup_fn on_cleanup;
136 memcached_free_fn call_free;
137 memcached_malloc_fn call_malloc;
138 memcached_realloc_fn call_realloc;
139 memcached_calloc_fn call_calloc;
140 memcached_trigger_key_fn get_key_failure;
141 memcached_trigger_delete_key_fn delete_trigger;
142 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
143 uint32_t number_of_replicas;
144 memcached_callback_st *callbacks;
145 };
146
147 LIBMEMCACHED_API
148 memcached_return_t memcached_version(memcached_st *ptr);
149
150 /* Public API */
151
152 LIBMEMCACHED_API
153 const char * memcached_lib_version(void);
154
155 LIBMEMCACHED_API
156 memcached_st *memcached_create(memcached_st *ptr);
157 LIBMEMCACHED_API
158 void memcached_free(memcached_st *ptr);
159 LIBMEMCACHED_API
160 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
161
162 LIBMEMCACHED_API
163 memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
164 time_t expiration);
165 LIBMEMCACHED_API
166 memcached_return_t memcached_increment(memcached_st *ptr,
167 const char *key, size_t key_length,
168 uint32_t offset,
169 uint64_t *value);
170 LIBMEMCACHED_API
171 memcached_return_t memcached_decrement(memcached_st *ptr,
172 const char *key, size_t key_length,
173 uint32_t offset,
174 uint64_t *value);
175
176 LIBMEMCACHED_API
177 memcached_return_t memcached_increment_by_key(memcached_st *ptr,
178 const char *master_key, size_t master_key_length,
179 const char *key, size_t key_length,
180 uint64_t offset,
181 uint64_t *value);
182
183 LIBMEMCACHED_API
184 memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
185 const char *master_key, size_t master_key_length,
186 const char *key, size_t key_length,
187 uint64_t offset,
188 uint64_t *value);
189
190 LIBMEMCACHED_API
191 memcached_return_t memcached_increment_with_initial(memcached_st *ptr,
192 const char *key,
193 size_t key_length,
194 uint64_t offset,
195 uint64_t initial,
196 time_t expiration,
197 uint64_t *value);
198 LIBMEMCACHED_API
199 memcached_return_t memcached_decrement_with_initial(memcached_st *ptr,
200 const char *key,
201 size_t key_length,
202 uint64_t offset,
203 uint64_t initial,
204 time_t expiration,
205 uint64_t *value);
206 LIBMEMCACHED_API
207 memcached_return_t memcached_increment_with_initial_by_key(memcached_st *ptr,
208 const char *master_key,
209 size_t master_key_length,
210 const char *key,
211 size_t key_length,
212 uint64_t offset,
213 uint64_t initial,
214 time_t expiration,
215 uint64_t *value);
216 LIBMEMCACHED_API
217 memcached_return_t memcached_decrement_with_initial_by_key(memcached_st *ptr,
218 const char *master_key,
219 size_t master_key_length,
220 const char *key,
221 size_t key_length,
222 uint64_t offset,
223 uint64_t initial,
224 time_t expiration,
225 uint64_t *value);
226 LIBMEMCACHED_API
227 void memcached_stat_free(memcached_st *, memcached_stat_st *);
228
229 LIBMEMCACHED_API
230 memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return_t *error);
231
232 LIBMEMCACHED_API
233 memcached_return_t memcached_stat_servername(memcached_stat_st *memc_stat, char *args,
234 const char *hostname, in_port_t port);
235
236 LIBMEMCACHED_API
237 memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration);
238
239 LIBMEMCACHED_API
240 memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
241
242 LIBMEMCACHED_API
243 void memcached_quit(memcached_st *ptr);
244
245 LIBMEMCACHED_API
246 const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
247
248 /* The two public hash bits */
249 LIBMEMCACHED_API
250 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm);
251
252 LIBMEMCACHED_API
253 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
254
255 LIBMEMCACHED_API
256 memcached_return_t memcached_flush_buffers(memcached_st *mem);
257
258 /* Server Public functions */
259
260 LIBMEMCACHED_API
261 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
262 const char *hostname,
263 in_port_t port);
264 LIBMEMCACHED_API
265 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
266 const char *filename);
267 LIBMEMCACHED_API
268 memcached_return_t memcached_server_add(memcached_st *ptr,
269 const char *hostname, in_port_t port);
270
271 LIBMEMCACHED_API
272 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
273 const char *hostname,
274 in_port_t port,
275 uint32_t weight);
276 LIBMEMCACHED_API
277 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
278 const char *filename,
279 uint32_t weight);
280 LIBMEMCACHED_API
281 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
282 in_port_t port,
283 uint32_t weight);
284 LIBMEMCACHED_API
285 void memcached_server_list_free(memcached_server_st *ptr);
286
287 LIBMEMCACHED_API
288 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
289
290 LIBMEMCACHED_API
291 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
292 const char *hostname,
293 in_port_t port,
294 memcached_return_t *error);
295 LIBMEMCACHED_API
296 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
297 const char *hostname,
298 in_port_t port,
299 uint32_t weight,
300 memcached_return_t *error);
301 LIBMEMCACHED_API
302 unsigned int memcached_server_list_count(memcached_server_st *ptr);
303
304 LIBMEMCACHED_API
305 memcached_server_st *memcached_servers_parse(const char *server_strings);
306
307 LIBMEMCACHED_API
308 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
309 const char *key, memcached_return_t *error);
310 LIBMEMCACHED_API
311 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
312 memcached_return_t *error);
313
314 LIBMEMCACHED_API
315 memcached_return_t memcached_delete_by_key(memcached_st *ptr,
316 const char *master_key, size_t master_key_length,
317 const char *key, size_t key_length,
318 time_t expiration);
319
320 LIBMEMCACHED_API
321 memcached_return_t memcached_fetch_execute(memcached_st *ptr,
322 memcached_execute_fn *callback,
323 void *context,
324 unsigned int number_of_callbacks);
325
326 LIBMEMCACHED_API
327 memcached_return_t memcached_dump(memcached_st *ptr, memcached_dump_fn *function, void *context, uint32_t number_of_callbacks);
328
329
330 LIBMEMCACHED_API
331 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
332 memcached_malloc_fn mem_malloc,
333 memcached_free_fn mem_free,
334 memcached_realloc_fn mem_realloc,
335 memcached_calloc_fn mem_calloc);
336
337 LIBMEMCACHED_API
338 void memcached_get_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_user_data(memcached_st *ptr);
346 LIBMEMCACHED_API
347 void *memcached_set_user_data(memcached_st *ptr, void *data);
348
349 LIBMEMCACHED_LOCAL
350 memcached_return_t run_distribution(memcached_st *ptr);
351
352 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
353 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
354
355 #ifdef __cplusplus
356 }
357 #endif
358
359
360 #endif /* __MEMCACHED_H__ */