Organize ketama a bit more (ie lets keep it in its own little basket).
[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 __LIBMEMCACHED_MEMCACHED_H__
14 #define __LIBMEMCACHED_MEMCACHED_H__
15
16 #include <inttypes.h>
17 #include <stdlib.h>
18 #include <sys/types.h>
19
20
21 #if !defined(__cplusplus)
22 # include <stdbool.h>
23 #endif
24
25 #include <libmemcached/visibility.h>
26 #include <libmemcached/configure.h>
27 #include <libmemcached/platform.h>
28 #include <libmemcached/constants.h>
29 #include <libmemcached/types.h>
30 #include <libmemcached/string.h>
31 #include <libmemcached/array.h>
32 #include <libmemcached/error.h>
33 #include <libmemcached/stats.h>
34 #include <libhashkit/hashkit.h>
35 // Everything above this line must be in the order specified.
36 #include <libmemcached/allocators.h>
37 #include <libmemcached/analyze.h>
38 #include <libmemcached/auto.h>
39 #include <libmemcached/behavior.h>
40 #include <libmemcached/callback.h>
41 #include <libmemcached/delete.h>
42 #include <libmemcached/dump.h>
43 #include <libmemcached/fetch.h>
44 #include <libmemcached/flush.h>
45 #include <libmemcached/flush_buffers.h>
46 #include <libmemcached/get.h>
47 #include <libmemcached/hash.h>
48 #include <libmemcached/options.h>
49 #include <libmemcached/parse.h>
50 #include <libmemcached/quit.h>
51 #include <libmemcached/result.h>
52 #include <libmemcached/server.h>
53 #include <libmemcached/server_list.h>
54 #include <libmemcached/storage.h>
55 #include <libmemcached/strerror.h>
56 #include <libmemcached/verbosity.h>
57 #include <libmemcached/version.h>
58 #include <libmemcached/sasl.h>
59
60 struct memcached_st {
61 /**
62 @note these are static and should not change without a call to behavior.
63 */
64 struct {
65 bool is_purging:1;
66 bool is_processing_input:1;
67 bool is_time_for_rebuild:1;
68 } state;
69 struct {
70 // Everything below here is pretty static.
71 bool auto_eject_hosts:1;
72 bool binary_protocol:1;
73 bool buffer_requests:1;
74 bool cork:1;
75 bool hash_with_prefix_key:1;
76 bool ketama_weighted:1;
77 bool no_block:1; // Don't block
78 bool no_reply:1;
79 bool randomize_replica_read:1;
80 bool reuse_memory:1;
81 bool support_cas:1;
82 bool tcp_nodelay:1;
83 bool use_cache_lookups:1;
84 bool use_sort_hosts:1;
85 bool use_udp:1;
86 bool verify_key:1;
87 bool tcp_keepalive:1;
88 bool ping_service:1;
89 } flags;
90 memcached_server_distribution_t distribution;
91 hashkit_st hashkit;
92 uint32_t number_of_hosts;
93 memcached_server_st *servers;
94 memcached_server_st *last_disconnected_server;
95 int32_t snd_timeout;
96 int32_t rcv_timeout;
97 uint32_t server_failure_limit;
98 uint32_t io_msg_watermark;
99 uint32_t io_bytes_watermark;
100 uint32_t io_key_prefetch;
101 uint32_t tcp_keepidle;
102 int cached_errno;
103 int32_t poll_timeout;
104 int32_t connect_timeout;
105 int32_t retry_timeout;
106 int send_size;
107 int recv_size;
108 void *user_data;
109 uint32_t number_of_replicas;
110 hashkit_st distribution_hashkit;
111 memcached_result_st result;
112
113 struct {
114 uint32_t continuum_count; // Ketama
115 uint32_t continuum_points_counter; // Ketama
116 time_t next_distribution_rebuild; // Ketama
117 memcached_continuum_item_st *continuum; // Ketama
118 } ketama;
119
120 struct _allocators_st {
121 memcached_calloc_fn calloc;
122 memcached_free_fn free;
123 memcached_malloc_fn malloc;
124 memcached_realloc_fn realloc;
125 void *context;
126 } allocators;
127
128 memcached_clone_fn on_clone;
129 memcached_cleanup_fn on_cleanup;
130 memcached_trigger_key_fn get_key_failure;
131 memcached_trigger_delete_key_fn delete_trigger;
132 memcached_callback_st *callbacks;
133 struct memcached_sasl_st sasl;
134 struct memcached_error_st *error_messages;
135 struct memcached_array_st *prefix_key;
136 struct {
137 struct memcached_array_st *filename;
138 } configure;
139 struct {
140 bool is_allocated:1;
141 } options;
142
143 };
144
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148
149 LIBMEMCACHED_API
150 void memcached_servers_reset(memcached_st *ptr);
151
152 LIBMEMCACHED_API
153 memcached_st *memcached_create(memcached_st *ptr);
154
155 LIBMEMCACHED_API
156 memcached_st *memcached_create_with_options(const char *string, size_t length);
157
158 LIBMEMCACHED_API
159 void memcached_free(memcached_st *ptr);
160
161 LIBMEMCACHED_API
162 memcached_return_t memcached_reset(memcached_st *ptr);
163
164 LIBMEMCACHED_API
165 void memcached_reset_last_disconnected_server(memcached_st *ptr);
166
167 LIBMEMCACHED_API
168 memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);
169
170 LIBMEMCACHED_API
171 void *memcached_get_user_data(const memcached_st *ptr);
172
173 LIBMEMCACHED_API
174 void *memcached_set_user_data(memcached_st *ptr, void *data);
175
176 LIBMEMCACHED_API
177 memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source);
178
179 LIBMEMCACHED_API
180 memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key);
181
182 LIBMEMCACHED_API
183 uint32_t memcached_server_count(const memcached_st *);
184
185 #ifdef __cplusplus
186 } // extern "C"
187 #endif
188
189
190 #ifdef __cplusplus
191 class Memcached : private memcached_st {
192 public:
193
194 Memcached()
195 {
196 memcached_create(this);
197 }
198
199 ~Memcached()
200 {
201 memcached_free(this);
202 }
203
204 Memcached(const Memcached& source)
205 {
206 memcached_clone(this, &source);
207 }
208
209 Memcached& operator=(const Memcached& source)
210 {
211 memcached_free(this);
212 memcached_clone(this, &source);
213
214 return *this;
215 }
216 };
217 #endif
218
219 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */
220