Merge in all of the new parser work.
[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/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/options.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 bool is_time_for_rebuild:1;
66 } state;
67 struct {
68 // Everything below here is pretty static.
69 bool auto_eject_hosts:1;
70 bool binary_protocol:1;
71 bool buffer_requests:1;
72 bool cork:1;
73 bool hash_with_prefix_key:1;
74 bool ketama_weighted:1;
75 bool no_block:1; // Don't block
76 bool no_reply:1;
77 bool randomize_replica_read:1;
78 bool reuse_memory:1;
79 bool support_cas:1;
80 bool tcp_nodelay:1;
81 bool use_cache_lookups:1;
82 bool use_sort_hosts:1;
83 bool use_udp:1;
84 bool verify_key:1;
85 bool tcp_keepalive:1;
86 bool load_from_file:1;
87 } flags;
88 memcached_server_distribution_t distribution;
89 hashkit_st hashkit;
90 uint32_t continuum_points_counter; // Ketama
91 uint32_t number_of_hosts;
92 memcached_server_st *servers;
93 memcached_server_st *last_disconnected_server;
94 int32_t snd_timeout;
95 int32_t rcv_timeout;
96 uint32_t server_failure_limit;
97 uint32_t io_msg_watermark;
98 uint32_t io_bytes_watermark;
99 uint32_t io_key_prefetch;
100 uint32_t tcp_keepidle;
101 int cached_errno;
102 int32_t poll_timeout;
103 int32_t connect_timeout;
104 int32_t retry_timeout;
105 uint32_t continuum_count; // Ketama
106 int send_size;
107 int recv_size;
108 void *user_data;
109 time_t next_distribution_rebuild; // Ketama
110 size_t prefix_key_length;
111 uint32_t number_of_replicas;
112 hashkit_st distribution_hashkit;
113 memcached_result_st result;
114 memcached_continuum_item_st *continuum; // Ketama
115
116 struct _allocators_st {
117 memcached_calloc_fn calloc;
118 memcached_free_fn free;
119 memcached_malloc_fn malloc;
120 memcached_realloc_fn realloc;
121 void *context;
122 } allocators;
123
124 memcached_clone_fn on_clone;
125 memcached_cleanup_fn on_cleanup;
126 memcached_trigger_key_fn get_key_failure;
127 memcached_trigger_delete_key_fn delete_trigger;
128 memcached_callback_st *callbacks;
129 struct memcached_sasl_st sasl;
130 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
131 struct {
132 bool is_allocated:1;
133 } options;
134
135 };
136
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
140
141 LIBMEMCACHED_API
142 void memcached_servers_reset(memcached_st *ptr);
143
144 LIBMEMCACHED_API
145 memcached_st *memcached_create(memcached_st *ptr);
146
147 LIBMEMCACHED_API
148 void memcached_free(memcached_st *ptr);
149
150 LIBMEMCACHED_API
151 void memcached_reset_last_disconnected_server(memcached_st *ptr);
152
153 LIBMEMCACHED_API
154 memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);
155
156 LIBMEMCACHED_API
157 void *memcached_get_user_data(const memcached_st *ptr);
158
159 LIBMEMCACHED_API
160 void *memcached_set_user_data(memcached_st *ptr, void *data);
161
162 LIBMEMCACHED_API
163 memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source);
164
165 LIBMEMCACHED_API
166 memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key);
167
168 LIBMEMCACHED_API
169 uint32_t memcached_server_count(const memcached_st *);
170
171 #ifdef __cplusplus
172 } // extern "C"
173 #endif
174
175
176 #ifdef __cplusplus
177 class Memcached : private memcached_st {
178 public:
179
180 Memcached()
181 {
182 memcached_create(this);
183 }
184
185 ~Memcached()
186 {
187 memcached_free(this);
188 }
189
190 Memcached(const Memcached& source)
191 {
192 memcached_clone(this, &source);
193 }
194
195 Memcached& operator=(const Memcached& source)
196 {
197 memcached_free(this);
198 memcached_clone(this, &source);
199
200 return *this;
201 }
202 };
203 #endif
204
205 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */
206