Fix for Debian linking issues.
[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 #include <libhashkit/hashkit.h>
33 // Everything above this line must be in the order specified.
34 #include <libmemcached/allocators.h>
35 #include <libmemcached/analyze.h>
36 #include <libmemcached/auto.h>
37 #include <libmemcached/behavior.h>
38 #include <libmemcached/callback.h>
39 #include <libmemcached/delete.h>
40 #include <libmemcached/dump.h>
41 #include <libmemcached/fetch.h>
42 #include <libmemcached/flush.h>
43 #include <libmemcached/flush_buffers.h>
44 #include <libmemcached/get.h>
45 #include <libmemcached/hash.h>
46 #include <libmemcached/parse.h>
47 #include <libmemcached/quit.h>
48 #include <libmemcached/result.h>
49 #include <libmemcached/server.h>
50 #include <libmemcached/storage.h>
51 #include <libmemcached/strerror.h>
52 #include <libmemcached/verbosity.h>
53 #include <libmemcached/version.h>
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 LIBMEMCACHED_API
60 void memcached_servers_reset(memcached_st *ptr);
61
62 LIBMEMCACHED_API
63 memcached_st *memcached_create(memcached_st *ptr);
64
65 LIBMEMCACHED_API
66 void memcached_free(memcached_st *ptr);
67
68 LIBMEMCACHED_API
69 memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);
70
71 LIBMEMCACHED_API
72 void *memcached_get_user_data(const memcached_st *ptr);
73
74 LIBMEMCACHED_API
75 void *memcached_set_user_data(memcached_st *ptr, void *data);
76
77
78 struct memcached_st {
79 /**
80 @note these are static and should not change without a call to behavior.
81 */
82 struct {
83 bool is_purging:1;
84 bool is_processing_input:1;
85 } state;
86 struct {
87 // Everything below here is pretty static.
88 bool auto_eject_hosts:1;
89 bool binary_protocol:1;
90 bool buffer_requests:1;
91 bool cork:1;
92 bool hash_with_prefix_key:1;
93 bool ketama_weighted:1;
94 bool no_block:1;
95 bool no_reply:1;
96 bool randomize_replica_read:1;
97 bool reuse_memory:1;
98 bool support_cas:1;
99 bool tcp_nodelay:1;
100 bool use_cache_lookups:1;
101 bool use_sort_hosts:1;
102 bool use_udp:1;
103 bool verify_key:1;
104 } flags;
105 memcached_server_distribution_t distribution;
106 hashkit_st hashkit;
107 uint32_t continuum_points_counter; // Ketama
108 uint32_t number_of_hosts;
109 memcached_server_st *servers;
110 memcached_server_st *last_disconnected_server;
111 int32_t snd_timeout;
112 int32_t rcv_timeout;
113 uint32_t server_failure_limit;
114 uint32_t io_msg_watermark;
115 uint32_t io_bytes_watermark;
116 uint32_t io_key_prefetch;
117 int cached_errno;
118 int32_t poll_timeout;
119 int32_t connect_timeout;
120 int32_t retry_timeout;
121 uint32_t continuum_count; // Ketama
122 int send_size;
123 int recv_size;
124 void *user_data;
125 time_t next_distribution_rebuild; // Ketama
126 size_t prefix_key_length;
127 uint32_t number_of_replicas;
128 hashkit_st distribution_hashkit;
129 memcached_result_st result;
130 memcached_continuum_item_st *continuum; // Ketama
131
132 struct _allocators_st {
133 memcached_calloc_fn calloc;
134 memcached_free_fn free;
135 memcached_malloc_fn malloc;
136 memcached_realloc_fn realloc;
137 void *context;
138 } allocators;
139
140 memcached_clone_fn on_clone;
141 memcached_cleanup_fn on_cleanup;
142 memcached_trigger_key_fn get_key_failure;
143 memcached_trigger_delete_key_fn delete_trigger;
144 memcached_callback_st *callbacks;
145 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
146 struct {
147 bool is_allocated:1;
148 } options;
149
150 #ifdef __cplusplus
151 memcached_st() :
152 state(),
153 flags(),
154 distribution(),
155 hashkit(),
156 continuum_points_counter(),
157 number_of_hosts(),
158 servers(),
159 last_disconnected_server(),
160 snd_timeout(),
161 rcv_timeout(),
162 server_failure_limit(),
163 io_msg_watermark(),
164 io_bytes_watermark(),
165 io_key_prefetch(),
166 cached_errno(),
167 poll_timeout(),
168 connect_timeout(),
169 retry_timeout(),
170 continuum_count(),
171 send_size(),
172 recv_size(),
173 user_data(),
174 next_distribution_rebuild(),
175 prefix_key_length(),
176 number_of_replicas(),
177 distribution_hashkit(),
178 result(),
179 continuum(),
180 allocators(),
181 on_clone(),
182 on_cleanup(),
183 get_key_failure(),
184 delete_trigger(),
185 callbacks(),
186 prefix_key(),
187 options()
188 {
189 memcached_create(this);
190 }
191
192 ~memcached_st()
193 {
194 memcached_free(this);
195 }
196
197 memcached_st(const memcached_st& source) :
198 state(),
199 flags(),
200 distribution(),
201 hashkit(),
202 continuum_points_counter(),
203 number_of_hosts(),
204 servers(),
205 last_disconnected_server(),
206 snd_timeout(),
207 rcv_timeout(),
208 server_failure_limit(),
209 io_msg_watermark(),
210 io_bytes_watermark(),
211 io_key_prefetch(),
212 cached_errno(),
213 poll_timeout(),
214 connect_timeout(),
215 retry_timeout(),
216 continuum_count(),
217 send_size(),
218 recv_size(),
219 user_data(),
220 next_distribution_rebuild(),
221 prefix_key_length(),
222 number_of_replicas(),
223 distribution_hashkit(),
224 result(),
225 continuum(),
226 allocators(),
227 on_clone(),
228 on_cleanup(),
229 get_key_failure(),
230 delete_trigger(),
231 callbacks(),
232 prefix_key(),
233 options()
234 {
235 memcached_clone(this, &source);
236 }
237
238 memcached_st& operator=(const memcached_st& source)
239 {
240 memcached_clone(this, &source);
241
242 return *this;
243 }
244
245 #endif
246 };
247
248 // Local Only Inline
249 static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
250 {
251 return &ptr->servers[server_key];
252 }
253
254
255 #ifdef __cplusplus
256 } // extern "C"
257 #endif
258
259
260 #endif /* __MEMCACHED_H__ */