Merging Trond
[m6w6/libmemcached] / libmemcached / memcached.h
1 /*
2 * Summary: interface for memcached server
3 * Description: main include file for libmemcached
4 *
5 * Copy: See Copyright for the status of this software.
6 *
7 * Author: Brian Aker
8 */
9
10 #ifndef __MEMCACHED_H__
11 #define __MEMCACHED_H__
12
13 #include <stdlib.h>
14 #include <inttypes.h>
15 #if !defined(__cplusplus)
16 # include <stdbool.h>
17 #endif
18 #include <sys/types.h>
19 #include <netinet/in.h>
20
21 #ifdef MEMCACHED_INTERNAL
22 #include <libmemcached/libmemcached_config.h>
23 #endif
24 #include <libmemcached/memcached_configure.h>
25 #include <libmemcached/memcached_constants.h>
26 #include <libmemcached/memcached_types.h>
27 #include <libmemcached/memcached_watchpoint.h>
28 #include <libmemcached/memcached_get.h>
29 #include <libmemcached/memcached_server.h>
30 #include <libmemcached/memcached_string.h>
31 #include <libmemcached/memcached_result.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /* These are Private and should not be used by applications */
38 #define MEMCACHED_VERSION_STRING_LENGTH 24
39
40 /* string value */
41 struct memcached_continuum_item_st {
42 uint32_t index;
43 uint32_t value;
44 };
45
46 #define LIBMEMCACHED_VERSION_STRING "0.30"
47
48 struct memcached_analysis_st {
49 uint32_t average_item_size;
50 uint32_t longest_uptime;
51 uint32_t least_free_server;
52 uint32_t most_consumed_server;
53 uint32_t oldest_server;
54 double pool_hit_ratio;
55 uint64_t most_used_bytes;
56 uint64_t least_remaining_bytes;
57 };
58
59 struct memcached_stat_st {
60 uint32_t connection_structures;
61 uint32_t curr_connections;
62 uint32_t curr_items;
63 uint32_t pid;
64 uint32_t pointer_size;
65 uint32_t rusage_system_microseconds;
66 uint32_t rusage_system_seconds;
67 uint32_t rusage_user_microseconds;
68 uint32_t rusage_user_seconds;
69 uint32_t threads;
70 uint32_t time;
71 uint32_t total_connections;
72 uint32_t total_items;
73 uint32_t uptime;
74 uint64_t bytes;
75 uint64_t bytes_read;
76 uint64_t bytes_written;
77 uint64_t cmd_get;
78 uint64_t cmd_set;
79 uint64_t evictions;
80 uint64_t get_hits;
81 uint64_t get_misses;
82 uint64_t limit_maxbytes;
83 char version[MEMCACHED_VERSION_STRING_LENGTH];
84 };
85
86 struct memcached_st {
87 uint8_t purging;
88 bool is_allocated;
89 uint8_t distribution;
90 uint8_t hash;
91 uint32_t continuum_points_counter;
92 memcached_server_st *hosts;
93 int32_t snd_timeout;
94 int32_t rcv_timeout;
95 uint32_t server_failure_limit;
96 uint32_t io_msg_watermark;
97 uint32_t io_bytes_watermark;
98 uint32_t io_key_prefetch;
99 uint32_t number_of_hosts;
100 uint32_t cursor_server;
101 int cached_errno;
102 uint32_t flags;
103 int32_t poll_timeout;
104 int32_t connect_timeout;
105 int32_t retry_timeout;
106 uint32_t continuum_count;
107 int send_size;
108 int recv_size;
109 void *user_data;
110 time_t next_distribution_rebuild;
111 size_t prefix_key_length;
112 memcached_hash hash_continuum;
113 memcached_result_st result;
114 memcached_continuum_item_st *continuum;
115 memcached_clone_func on_clone;
116 memcached_cleanup_func on_cleanup;
117 memcached_free_function call_free;
118 memcached_malloc_function call_malloc;
119 memcached_realloc_function call_realloc;
120 memcached_calloc_function call_calloc;
121 memcached_trigger_key get_key_failure;
122 memcached_trigger_delete_key delete_trigger;
123 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
124 };
125
126
127 /* Public API */
128 const char * memcached_lib_version(void);
129
130 memcached_st *memcached_create(memcached_st *ptr);
131 void memcached_free(memcached_st *ptr);
132 memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr);
133
134 memcached_return memcached_delete(memcached_st *ptr, const char *key, size_t key_length,
135 time_t expiration);
136 memcached_return memcached_increment(memcached_st *ptr,
137 const char *key, size_t key_length,
138 uint32_t offset,
139 uint64_t *value);
140 memcached_return memcached_decrement(memcached_st *ptr,
141 const char *key, size_t key_length,
142 uint32_t offset,
143 uint64_t *value);
144 memcached_return memcached_increment_with_initial(memcached_st *ptr,
145 const char *key,
146 size_t key_length,
147 uint64_t offset,
148 uint64_t initial,
149 time_t expiration,
150 uint64_t *value);
151 memcached_return memcached_decrement_with_initial(memcached_st *ptr,
152 const char *key,
153 size_t key_length,
154 uint64_t offset,
155 uint64_t initial,
156 time_t expiration,
157 uint64_t *value);
158 void memcached_stat_free(memcached_st *, memcached_stat_st *);
159 memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error);
160 memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args,
161 char *hostname, unsigned int port);
162 memcached_return memcached_flush(memcached_st *ptr, time_t expiration);
163 memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
164 void memcached_quit(memcached_st *ptr);
165 char *memcached_strerror(memcached_st *ptr, memcached_return rc);
166 memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, uint64_t data);
167 uint64_t memcached_behavior_get(memcached_st *ptr, memcached_behavior flag);
168
169 /* The two public hash bits */
170 uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash hash_algorithm);
171 uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_length);
172
173 memcached_return memcached_flush_buffers(memcached_st *mem);
174
175 /* Server Public functions */
176
177 memcached_return memcached_server_add_udp(memcached_st *ptr,
178 const char *hostname,
179 unsigned int port);
180 memcached_return memcached_server_add_unix_socket(memcached_st *ptr,
181 const char *filename);
182 memcached_return memcached_server_add(memcached_st *ptr, const char *hostname,
183 unsigned int port);
184
185 memcached_return memcached_server_add_udp_with_weight(memcached_st *ptr,
186 const char *hostname,
187 unsigned int port,
188 uint32_t weight);
189 memcached_return memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
190 const char *filename,
191 uint32_t weight);
192 memcached_return memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
193 unsigned int port,
194 uint32_t weight);
195 void memcached_server_list_free(memcached_server_st *ptr);
196 memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *list);
197
198 memcached_server_st *memcached_server_list_append(memcached_server_st *ptr,
199 const char *hostname,
200 unsigned int port,
201 memcached_return *error);
202 memcached_server_st *memcached_server_list_append_with_weight(memcached_server_st *ptr,
203 const char *hostname,
204 unsigned int port,
205 uint32_t weight,
206 memcached_return *error);
207 unsigned int memcached_server_list_count(memcached_server_st *ptr);
208 memcached_server_st *memcached_servers_parse(const char *server_strings);
209
210 char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat,
211 const char *key, memcached_return *error);
212 char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat,
213 memcached_return *error);
214
215 memcached_return memcached_delete_by_key(memcached_st *ptr,
216 const char *master_key, size_t master_key_length,
217 const char *key, size_t key_length,
218 time_t expiration);
219
220 memcached_return memcached_fetch_execute(memcached_st *ptr,
221 memcached_execute_function *callback,
222 void *context,
223 unsigned int number_of_callbacks);
224
225 memcached_return memcached_callback_set(memcached_st *ptr,
226 memcached_callback flag,
227 void *data);
228 void *memcached_callback_get(memcached_st *ptr,
229 memcached_callback flag,
230 memcached_return *error);
231
232 memcached_return memcached_dump(memcached_st *ptr, memcached_dump_func *function, void *context, uint32_t number_of_callbacks);
233
234
235 memcached_return memcached_set_memory_allocators(memcached_st *ptr,
236 memcached_malloc_function mem_malloc,
237 memcached_free_function mem_free,
238 memcached_realloc_function mem_realloc,
239 memcached_calloc_function mem_calloc);
240
241 void memcached_get_memory_allocators(memcached_st *ptr,
242 memcached_malloc_function *mem_malloc,
243 memcached_free_function *mem_free,
244 memcached_realloc_function *mem_realloc,
245 memcached_calloc_function *mem_calloc);
246
247 void *memcached_get_user_data(memcached_st *ptr);
248 void *memcached_set_user_data(memcached_st *ptr, void *data);
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #include <libmemcached/memcached_storage.h>
255
256 #ifdef MEMCACHED_INTERNAL
257 #include <libmemcached/memcached_internal.h>
258 #endif
259
260 #endif /* __MEMCACHED_H__ */