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