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