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