Merge Monty
[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/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 bool is_processing_input:1;
53 } options;
54 memcached_server_distribution_t distribution;
55 memcached_hash_t hash;
56 uint32_t continuum_points_counter; // Ketama
57 memcached_server_st *servers;
58 memcached_server_st *last_disconnected_server;
59 int32_t snd_timeout;
60 int32_t rcv_timeout;
61 uint32_t server_failure_limit;
62 uint32_t io_msg_watermark;
63 uint32_t io_bytes_watermark;
64 uint32_t io_key_prefetch;
65 uint32_t number_of_hosts;
66 int cached_errno;
67 /**
68 @note these are static and should not change without a call to behavior.
69 */
70 struct {
71 bool auto_eject_hosts:1;
72 bool binary_protocol:1;
73 bool buffer_requests:1;
74 bool hash_with_prefix_key:1;
75 bool ketama_weighted:1;
76 bool no_block:1;
77 bool no_reply:1;
78 bool randomize_replica_read:1;
79 bool reuse_memory:1;
80 bool support_cas:1;
81 bool tcp_nodelay:1;
82 bool use_cache_lookups:1;
83 bool use_sort_hosts:1;
84 bool use_udp:1;
85 bool verify_key:1;
86 } flags;
87 int32_t poll_timeout;
88 int32_t connect_timeout;
89 int32_t retry_timeout;
90 uint32_t continuum_count; // Ketama
91 int send_size;
92 int recv_size;
93 void *user_data;
94 time_t next_distribution_rebuild; // Ketama
95 size_t prefix_key_length;
96 uint32_t number_of_replicas;
97 memcached_hash_t distribution_hash;
98 memcached_result_st result;
99 memcached_continuum_item_st *continuum; // Ketama
100 memcached_clone_fn on_clone;
101 memcached_cleanup_fn on_cleanup;
102 memcached_free_fn call_free;
103 memcached_malloc_fn call_malloc;
104 memcached_realloc_fn call_realloc;
105 memcached_calloc_fn call_calloc;
106 memcached_trigger_key_fn get_key_failure;
107 memcached_trigger_delete_key_fn delete_trigger;
108 memcached_callback_st *callbacks;
109 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
110 };
111
112 LIBMEMCACHED_API
113 memcached_return_t memcached_version(memcached_st *ptr);
114
115 LIBMEMCACHED_API
116 void memcached_servers_reset(memcached_st *ptr);
117
118 // Local Only Inline
119 static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
120 {
121 return &ptr->servers[server_key];
122 }
123
124 /* Public API */
125
126 LIBMEMCACHED_API
127 const char * memcached_lib_version(void);
128
129 LIBMEMCACHED_API
130 memcached_st *memcached_create(memcached_st *ptr);
131 LIBMEMCACHED_API
132 void memcached_free(memcached_st *ptr);
133 LIBMEMCACHED_API
134 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
135
136 LIBMEMCACHED_API
137 memcached_return_t memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
138 time_t expiration);
139
140 LIBMEMCACHED_API
141 memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration);
142
143 LIBMEMCACHED_API
144 memcached_return_t memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
145
146 LIBMEMCACHED_API
147 void memcached_quit(memcached_st *ptr);
148
149 LIBMEMCACHED_API
150 const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
151
152 /* The two public hash bits */
153 LIBMEMCACHED_API
154 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm);
155
156 LIBMEMCACHED_API
157 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
158
159 LIBMEMCACHED_API
160 memcached_return_t memcached_flush_buffers(memcached_st *mem);
161
162 /* Server Public functions */
163
164 LIBMEMCACHED_API
165 memcached_return_t memcached_server_add_udp(memcached_st *ptr,
166 const char *hostname,
167 in_port_t port);
168 LIBMEMCACHED_API
169 memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
170 const char *filename);
171 LIBMEMCACHED_API
172 memcached_return_t memcached_server_add(memcached_st *ptr,
173 const char *hostname, in_port_t port);
174
175 LIBMEMCACHED_API
176 memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
177 const char *hostname,
178 in_port_t port,
179 uint32_t weight);
180 LIBMEMCACHED_API
181 memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
182 const char *filename,
183 uint32_t weight);
184 LIBMEMCACHED_API
185 memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
186 in_port_t port,
187 uint32_t weight);
188 LIBMEMCACHED_API
189 void memcached_server_list_free(memcached_server_st *ptr);
190
191 LIBMEMCACHED_API
192 memcached_return_t memcached_server_push(memcached_st *ptr, memcached_server_st *list);
193
194 LIBMEMCACHED_API
195 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
196 const char *hostname,
197 in_port_t port,
198 memcached_return_t *error);
199 LIBMEMCACHED_API
200 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
201 const char *hostname,
202 in_port_t port,
203 uint32_t weight,
204 memcached_return_t *error);
205 LIBMEMCACHED_API
206 unsigned int memcached_server_list_count(memcached_server_st *ptr);
207
208 LIBMEMCACHED_API
209 memcached_server_st *memcached_servers_parse(const char *server_strings);
210
211 LIBMEMCACHED_API
212 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat,
213 const char *key, memcached_return_t *error);
214 LIBMEMCACHED_API
215 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat,
216 memcached_return_t *error);
217
218 LIBMEMCACHED_API
219 memcached_return_t memcached_delete_by_key(memcached_st *ptr,
220 const char *master_key, size_t master_key_length,
221 const char *key, size_t key_length,
222 time_t expiration);
223
224 LIBMEMCACHED_API
225 memcached_return_t memcached_fetch_execute(memcached_st *ptr,
226 memcached_execute_fn *callback,
227 void *context,
228 unsigned int number_of_callbacks);
229
230 LIBMEMCACHED_API
231 memcached_return_t memcached_set_memory_allocators(memcached_st *ptr,
232 memcached_malloc_fn mem_malloc,
233 memcached_free_fn mem_free,
234 memcached_realloc_fn mem_realloc,
235 memcached_calloc_fn mem_calloc);
236
237 LIBMEMCACHED_API
238 void memcached_get_memory_allocators(memcached_st *ptr,
239 memcached_malloc_fn *mem_malloc,
240 memcached_free_fn *mem_free,
241 memcached_realloc_fn *mem_realloc,
242 memcached_calloc_fn *mem_calloc);
243
244 LIBMEMCACHED_API
245 void *memcached_get_user_data(memcached_st *ptr);
246 LIBMEMCACHED_API
247 void *memcached_set_user_data(memcached_st *ptr, void *data);
248
249 LIBMEMCACHED_LOCAL
250 memcached_return_t run_distribution(memcached_st *ptr);
251
252 #define memcached_is_allocated(__object) ((__object)->options.is_allocated)
253 #define memcached_is_initialized(__object) ((__object)->options.is_initialized)
254
255 #ifdef __cplusplus
256 }
257 #endif
258
259
260 #endif /* __MEMCACHED_H__ */