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