Merge in all scanner tree + virtual buckets.
[awesomized/libmemcached] / libmemcached / memcached.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached library
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38 #ifndef __LIBMEMCACHED_MEMCACHED_H__
39 #define __LIBMEMCACHED_MEMCACHED_H__
40
41 #include <inttypes.h>
42 #include <stdlib.h>
43 #include <sys/types.h>
44
45
46 #if !defined(__cplusplus)
47 # include <stdbool.h>
48 #endif
49
50 #include <libmemcached/visibility.h>
51 #include <libmemcached/configure.h>
52 #include <libmemcached/platform.h>
53 #include <libmemcached/constants.h>
54 #include <libmemcached/types.h>
55 #include <libmemcached/string.h>
56 #include <libmemcached/array.h>
57 #include <libmemcached/error.h>
58 #include <libmemcached/stats.h>
59 #include <libhashkit/hashkit.h>
60 // Everything above this line must be in the order specified.
61 #include <libmemcached/allocators.h>
62 #include <libmemcached/analyze.h>
63 #include <libmemcached/auto.h>
64 #include <libmemcached/behavior.h>
65 #include <libmemcached/callback.h>
66 #include <libmemcached/delete.h>
67 #include <libmemcached/dump.h>
68 #include <libmemcached/fetch.h>
69 #include <libmemcached/flush.h>
70 #include <libmemcached/flush_buffers.h>
71 #include <libmemcached/get.h>
72 #include <libmemcached/hash.h>
73 #include <libmemcached/options.h>
74 #include <libmemcached/parse.h>
75 #include <libmemcached/quit.h>
76 #include <libmemcached/result.h>
77 #include <libmemcached/server.h>
78 #include <libmemcached/server_list.h>
79 #include <libmemcached/storage.h>
80 #include <libmemcached/strerror.h>
81 #include <libmemcached/verbosity.h>
82 #include <libmemcached/version.h>
83 #include <libmemcached/sasl.h>
84
85 struct memcached_st {
86 /**
87 @note these are static and should not change without a call to behavior.
88 */
89 struct {
90 bool is_purging:1;
91 bool is_processing_input:1;
92 bool is_time_for_rebuild:1;
93 } state;
94
95 struct {
96 // Everything below here is pretty static.
97 bool auto_eject_hosts:1;
98 bool binary_protocol:1;
99 bool buffer_requests:1;
100 bool hash_with_prefix_key:1;
101 bool no_block:1; // Don't block
102 bool no_reply:1;
103 bool randomize_replica_read:1;
104 bool reuse_memory:1;
105 bool support_cas:1;
106 bool tcp_nodelay:1;
107 bool use_cache_lookups:1;
108 bool use_sort_hosts:1;
109 bool use_udp:1;
110 bool verify_key:1;
111 bool tcp_keepalive:1;
112 } flags;
113
114 memcached_server_distribution_t distribution;
115 hashkit_st hashkit;
116 uint32_t number_of_hosts;
117 memcached_server_st *servers;
118 memcached_server_st *last_disconnected_server;
119 int32_t snd_timeout;
120 int32_t rcv_timeout;
121 uint32_t server_failure_limit;
122 uint32_t io_msg_watermark;
123 uint32_t io_bytes_watermark;
124 uint32_t io_key_prefetch;
125 uint32_t tcp_keepidle;
126 int32_t poll_timeout;
127 int32_t connect_timeout;
128 int32_t retry_timeout;
129 int send_size;
130 int recv_size;
131 void *user_data;
132 uint32_t number_of_replicas;
133 hashkit_st distribution_hashkit;
134 memcached_result_st result;
135
136 struct {
137 bool weighted;
138 uint32_t continuum_count; // Ketama
139 uint32_t continuum_points_counter; // Ketama
140 time_t next_distribution_rebuild; // Ketama
141 memcached_continuum_item_st *continuum; // Ketama
142 } ketama;
143
144 struct memcached_virtual_bucket_t *virtual_bucket;
145
146 struct _allocators_st {
147 memcached_calloc_fn calloc;
148 memcached_free_fn free;
149 memcached_malloc_fn malloc;
150 memcached_realloc_fn realloc;
151 void *context;
152 } allocators;
153
154 memcached_clone_fn on_clone;
155 memcached_cleanup_fn on_cleanup;
156 memcached_trigger_key_fn get_key_failure;
157 memcached_trigger_delete_key_fn delete_trigger;
158 memcached_callback_st *callbacks;
159 struct memcached_sasl_st sasl;
160 struct memcached_error_st *error_messages;
161 struct memcached_array_st *prefix_key;
162 struct {
163 struct memcached_array_st *filename;
164 } configure;
165 struct {
166 bool is_allocated:1;
167 } options;
168
169 };
170
171 #ifdef __cplusplus
172 extern "C" {
173 #endif
174
175 LIBMEMCACHED_API
176 void memcached_servers_reset(memcached_st *ptr);
177
178 LIBMEMCACHED_API
179 memcached_st *memcached_create(memcached_st *ptr);
180
181 LIBMEMCACHED_API
182 memcached_st *memcached_create_with_options(const char *string, size_t length);
183
184 LIBMEMCACHED_API
185 void memcached_free(memcached_st *ptr);
186
187 LIBMEMCACHED_API
188 memcached_return_t memcached_reset(memcached_st *ptr);
189
190 LIBMEMCACHED_API
191 void memcached_reset_last_disconnected_server(memcached_st *ptr);
192
193 LIBMEMCACHED_API
194 memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);
195
196 LIBMEMCACHED_API
197 void *memcached_get_user_data(const memcached_st *ptr);
198
199 LIBMEMCACHED_API
200 void *memcached_set_user_data(memcached_st *ptr, void *data);
201
202 LIBMEMCACHED_API
203 memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source);
204
205 LIBMEMCACHED_API
206 memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key);
207
208 LIBMEMCACHED_API
209 uint32_t memcached_server_count(const memcached_st *);
210
211 #ifdef __cplusplus
212 } // extern "C"
213 #endif
214
215
216 #ifdef __cplusplus
217 class Memcached : private memcached_st {
218 public:
219
220 Memcached()
221 {
222 memcached_create(this);
223 }
224
225 ~Memcached()
226 {
227 memcached_free(this);
228 }
229
230 Memcached(const Memcached& source)
231 {
232 memcached_clone(this, &source);
233 }
234
235 Memcached& operator=(const Memcached& source)
236 {
237 memcached_free(this);
238 memcached_clone(this, &source);
239
240 return *this;
241 }
242 };
243 #endif
244
245 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */
246