More Cleanup
[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 __LIBMEMCACHED_MEMCACHED_H__
14 #define __LIBMEMCACHED_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 #ifdef __cplusplus
78 } // extern "C"
79 #endif
80
81
82 struct memcached_st {
83 /**
84 @note these are static and should not change without a call to behavior.
85 */
86 struct {
87 bool is_purging:1;
88 bool is_processing_input:1;
89 } state;
90 struct {
91 // Everything below here is pretty static.
92 bool auto_eject_hosts:1;
93 bool binary_protocol:1;
94 bool buffer_requests:1;
95 bool cork:1;
96 bool hash_with_prefix_key:1;
97 bool ketama_weighted:1;
98 bool no_block:1;
99 bool no_reply:1;
100 bool randomize_replica_read:1;
101 bool reuse_memory:1;
102 bool support_cas:1;
103 bool tcp_nodelay:1;
104 bool use_cache_lookups:1;
105 bool use_sort_hosts:1;
106 bool use_udp:1;
107 bool verify_key:1;
108 } flags;
109 memcached_server_distribution_t distribution;
110 hashkit_st hashkit;
111 uint32_t continuum_points_counter; // Ketama
112 uint32_t number_of_hosts;
113 memcached_server_st *servers;
114 memcached_server_st *last_disconnected_server;
115 int32_t snd_timeout;
116 int32_t rcv_timeout;
117 uint32_t server_failure_limit;
118 uint32_t io_msg_watermark;
119 uint32_t io_bytes_watermark;
120 uint32_t io_key_prefetch;
121 int cached_errno;
122 int32_t poll_timeout;
123 int32_t connect_timeout;
124 int32_t retry_timeout;
125 uint32_t continuum_count; // Ketama
126 int send_size;
127 int recv_size;
128 void *user_data;
129 time_t next_distribution_rebuild; // Ketama
130 size_t prefix_key_length;
131 uint32_t number_of_replicas;
132 hashkit_st distribution_hashkit;
133 memcached_result_st result;
134 memcached_continuum_item_st *continuum; // Ketama
135
136 struct _allocators_st {
137 memcached_calloc_fn calloc;
138 memcached_free_fn free;
139 memcached_malloc_fn malloc;
140 memcached_realloc_fn realloc;
141 void *context;
142 } allocators;
143
144 memcached_clone_fn on_clone;
145 memcached_cleanup_fn on_cleanup;
146 memcached_trigger_key_fn get_key_failure;
147 memcached_trigger_delete_key_fn delete_trigger;
148 memcached_callback_st *callbacks;
149 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
150 struct {
151 bool is_allocated:1;
152 } options;
153
154 #ifdef __cplusplus
155 memcached_st() :
156 state(),
157 flags(),
158 distribution(),
159 hashkit(),
160 continuum_points_counter(),
161 number_of_hosts(),
162 servers(),
163 last_disconnected_server(),
164 snd_timeout(),
165 rcv_timeout(),
166 server_failure_limit(),
167 io_msg_watermark(),
168 io_bytes_watermark(),
169 io_key_prefetch(),
170 cached_errno(),
171 poll_timeout(),
172 connect_timeout(),
173 retry_timeout(),
174 continuum_count(),
175 send_size(),
176 recv_size(),
177 user_data(),
178 next_distribution_rebuild(),
179 prefix_key_length(),
180 number_of_replicas(),
181 distribution_hashkit(),
182 result(),
183 continuum(),
184 allocators(),
185 on_clone(),
186 on_cleanup(),
187 get_key_failure(),
188 delete_trigger(),
189 callbacks(),
190 prefix_key(),
191 options()
192 {
193 memcached_create(this);
194 }
195
196 ~memcached_st()
197 {
198 memcached_free(this);
199 }
200
201 memcached_st(const memcached_st& source) :
202 state(),
203 flags(),
204 distribution(),
205 hashkit(),
206 continuum_points_counter(),
207 number_of_hosts(),
208 servers(),
209 last_disconnected_server(),
210 snd_timeout(),
211 rcv_timeout(),
212 server_failure_limit(),
213 io_msg_watermark(),
214 io_bytes_watermark(),
215 io_key_prefetch(),
216 cached_errno(),
217 poll_timeout(),
218 connect_timeout(),
219 retry_timeout(),
220 continuum_count(),
221 send_size(),
222 recv_size(),
223 user_data(),
224 next_distribution_rebuild(),
225 prefix_key_length(),
226 number_of_replicas(),
227 distribution_hashkit(),
228 result(),
229 continuum(),
230 allocators(),
231 on_clone(),
232 on_cleanup(),
233 get_key_failure(),
234 delete_trigger(),
235 callbacks(),
236 prefix_key(),
237 options()
238 {
239 memcached_clone(this, &source);
240 }
241
242 memcached_st& operator=(const memcached_st& source)
243 {
244 memcached_free(this);
245 memcached_clone(this, &source);
246
247 return *this;
248 }
249
250 #endif
251 };
252
253
254 // Local Only Inline
255 static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key)
256 {
257 return &ptr->servers[server_key];
258 }
259
260 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */