1 module memcache.structd;
2 
3 import core.stdc.time;
4 import core.sys.posix.pthread;
5 
6 public import memcache;
7 extern (C):
8 
9 alias int in_port_t;
10 
11 struct memcached_array_st;
12 struct memcached_error_t;
13 
14 // All of the flavors of memcache_server_st
15 struct memcached_instance_st;
16 
17 struct memcached_virtual_bucket_t;
18 
19 // The following two structures are internal, and never exposed to users.
20 struct memcached_string_t;
21 struct memcached_continuum_item_st;
22 
23 version (sasl)
24 {
25 }
26 else
27 {
28     alias void sasl_callback_t;
29 }
30 
31 struct memcached_sasl_st
32 {
33     sasl_callback_t* callbacks;
34     /*
35 	** Did we allocate data inside the callbacks, or did the user
36 	** supply that.
37 	*/
38     bool is_allocated;
39 };
40 
41 //memcached.h
42 struct memcached_st
43 {
44     /**
45     @note these are static and should not change without a call to behavior.
46 	*/
47     align(1) struct struct_state
48     {
49         bool is_purging;
50         bool is_processing_input;
51         bool is_time_for_rebuild;
52         bool is_parsing;
53     };
54 
55     struct_state state;
56 
57     align(1) struct struct_flags
58     {
59         // Everything below here is pretty static.
60         bool auto_eject_hosts;
61         bool binary_protocol;
62         bool buffer_requests;
63         bool hash_with_namespace;
64         bool no_block; // Don't block
65         bool reply;
66         bool randomize_replica_read;
67         bool support_cas;
68         bool tcp_nodelay;
69         bool use_sort_hosts;
70         bool use_udp;
71         bool verify_key;
72         bool tcp_keepalive;
73         bool is_aes;
74         bool is_fetching_version;
75         bool not_used;
76     };
77 
78     struct_flags flags;
79 
80     memcached_server_distribution_t distribution;
81     hashkit_st hashkit;
82     struct struct_server_info
83     {
84         uint Version;
85     };
86     struct_server_info server_info;
87     uint number_of_hosts;
88     memcached_instance_st* servers;
89     memcached_instance_st* last_disconnected_server;
90     int snd_timeout;
91     int rcv_timeout;
92     uint server_failure_limit;
93     uint server_timeout_limit;
94     uint io_msg_watermark;
95     uint io_bytes_watermark;
96     uint io_key_prefetch;
97     uint tcp_keepidle;
98     int poll_timeout;
99     int connect_timeout; // How long we will wait on connect() before we will timeout
100     int retry_timeout;
101     int dead_timeout;
102     int send_size;
103     int recv_size;
104     void* user_data;
105     ulong query_id;
106     uint number_of_replicas;
107     memcached_result_st result;
108 
109     struct struct_ketama
110     {
111         bool weighted_;
112         uint continuum_count; // Ketama
113         uint continuum_points_counter; // Ketama
114         time_t next_distribution_rebuild; // Ketama
115         memcached_continuum_item_st* continuum; // Ketama
116     };
117     struct_ketama ketama;
118 
119     memcached_virtual_bucket_t* virtual_bucket;
120 
121     memcached_allocator_t allocators;
122 
123     memcached_clone_fn on_clone;
124     memcached_cleanup_fn on_cleanup;
125     memcached_trigger_key_fn get_key_failure;
126     memcached_trigger_delete_key_fn delete_trigger;
127     memcached_callback_st* callbacks;
128     memcached_sasl_st sasl;
129     memcached_error_t* error_messages;
130     memcached_array_st* _namespace;
131     struct struct_configure
132     {
133         uint initial_pool_size;
134         uint max_pool_size;
135         int Version; // This is used by pool and others to determine if the memcached_st is out of date.
136         memcached_array_st* filename;
137     };
138     struct_configure configure;
139     struct struct_options
140     {
141         bool is_allocated;
142     };
143     struct_options options;
144 };
145 
146 //string.h
147 struct memcached_string_st
148 {
149     char* end;
150     char* string;
151     size_t current_size;
152     memcached_st* root;
153     struct options_type
154     {
155         align(1) bool is_allocated;
156         align(1) bool is_initialized;
157     };
158     options_type options;
159 };
160 
161 //stat.h
162 struct memcached_stat_st
163 {
164     ulong connection_structures;
165     ulong curr_connections;
166     ulong curr_items;
167     /*pid_t*/
168     int pid;
169     ulong pointer_size;
170     ulong rusage_system_microseconds;
171     ulong rusage_system_seconds;
172     ulong rusage_user_microseconds;
173     ulong rusage_user_seconds;
174     ulong threads;
175     ulong time;
176     ulong total_connections;
177     ulong total_items;
178     ulong uptime;
179     ulong bytes;
180     ulong bytes_read;
181     ulong bytes_written;
182     ulong cmd_get;
183     ulong cmd_set;
184     ulong evictions;
185     ulong get_hits;
186     ulong get_misses;
187     ulong limit_maxbytes;
188     char[MEMCACHED_VERSION_STRING_LENGTH] Version;
189     void* __future; // @todo create a new structure to place here for future usage
190     memcached_st* root;
191 };
192 //result.h
193 struct memcached_result_st
194 {
195     uint item_flags;
196     time_t item_expiration;
197     size_t key_length;
198     ulong item_cas;
199     memcached_st* root;
200     memcached_string_st value;
201     ulong numeric_value;
202     ulong count;
203     char[MEMCACHED_MAX_KEY] item_key;
204     align(1) struct struct_options
205     {
206         bool is_allocated;
207         bool is_initialized;
208     };
209     struct_options options;
210     /* Add result callback function */
211 };
212 
213 struct memcached_server_st
214 {
215     align(1) struct struct_options
216     {
217         bool is_allocated;
218         bool is_initialized;
219         bool is_shutting_down;
220         bool is_dead;
221     };
222     struct_options options;
223     uint number_of_hosts;
224     uint cursor_active;
225     in_port_t port;
226     uint io_bytes_sent; /* # bytes sent since last read */
227     uint request_id;
228     uint server_failure_counter;
229     ulong server_failure_counter_query_id;
230     uint server_timeout_counter;
231     ulong server_timeout_counter_query_id;
232     uint weight;
233     uint Version;
234     memcached_server_state_t state;
235     struct struct_io_wait_count
236     {
237         uint read;
238         uint write;
239         uint timeouts;
240         size_t _bytes_read;
241     };
242     struct_io_wait_count io_wait_count;
243     ubyte major_version; // Default definition of UINT8_MAX means that it has not been set.
244     ubyte micro_version; // ditto, and note that this is the third, not second Version bit
245     ubyte minor_version; // ditto
246     memcached_connection_t type;
247     time_t next_retry;
248     memcached_st* root;
249     ulong limit_maxbytes;
250     memcached_error_t* error_messages;
251     char[MEMCACHED_NI_MAXHOST] hostname;
252 };
253 //callback.h
254 struct memcached_callback_st
255 {
256     memcached_execute_fn* callback;
257     void* context;
258     uint number_of_callback;
259 };
260 //analysis.d
261 struct memcached_analysis_st
262 {
263     memcached_st* root;
264     uint average_item_size;
265     uint longest_uptime;
266     uint least_free_server;
267     uint most_consumed_server;
268     uint oldest_server;
269     double pool_hit_ratio;
270     ulong most_used_bytes;
271     ulong least_remaining_bytes;
272 };
273 //allocator.d
274 struct memcached_allocator_t
275 {
276     memcached_calloc_fn calloc;
277     memcached_free_fn free;
278     memcached_malloc_fn malloc;
279     memcached_realloc_fn realloc;
280     void* context;
281 };
282 
283 alias memcached_server_list_st = memcached_server_st*;
284 //deprecated_types
285 /**
286 @note The following definitions are just here for backwards compatibility.
287 */
288 
289 alias memcached_return_t memcached_return;
290 alias memcached_server_distribution_t memcached_server_distribution;
291 alias memcached_behavior_t memcached_behavior;
292 alias memcached_callback_t memcached_callback;
293 alias memcached_hash_t memcached_hash;
294 alias memcached_connection_t memcached_connection;
295 alias memcached_clone_fn memcached_clone_func;
296 alias memcached_cleanup_fn memcached_cleanup_func;
297 alias memcached_execute_fn memcached_execute_function;
298 alias memcached_server_fn memcached_server_function;
299 alias memcached_trigger_key_fn memcached_trigger_key;
300 alias memcached_trigger_delete_key_fn memcached_trigger_delete_key;
301 alias memcached_dump_fn memcached_dump_func;
302 alias memcached_instance_st* memcached_server_instance_st;
303 
304 //alloc.d
305 alias memcached_free_fn = void function(const memcached_st* ptr, void* mem, void* context);
306 alias memcached_malloc_fn = void* function(const memcached_st* ptr, const size_t size,
307     void* context);
308 alias memcached_realloc_fn = void* function(const memcached_st* ptr, void* mem,
309     const size_t size, void* context);
310 alias memcached_calloc_fn = void* function(const memcached_st* ptr, size_t nelem,
311     const size_t elsize, void* context);
312 
313 //callbacks.h
314 alias memcached_execute_fn = memcached_return_t function(const memcached_st* ptr,
315     memcached_result_st* result, void* context);
316 alias memcached_server_fn = memcached_return_t function(const memcached_st* ptr,
317     const memcached_instance_st* server, void* context);
318 alias memcached_stat_fn = memcached_return_t function(
319     const memcached_instance_st* server, const char* key, size_t key_length,
320     const char* value, size_t value_length, void* context);
321 
322 //triggers.h
323 alias memcached_clone_fn = memcached_return_t function(memcached_st* destination,
324     const memcached_st* source);
325 alias memcached_cleanup_fn = memcached_return_t function(const memcached_st* ptr);
326 
327 /**
328 Trigger functions.
329 */
330 alias memcached_trigger_key_fn = memcached_return_t function(
331     const memcached_st* ptr, const char* key, size_t key_length, memcached_result_st* result);
332 alias memcached_trigger_delete_key_fn = memcached_return_t function(
333     const memcached_st* ptr, const char* key, size_t key_length);
334 
335 alias memcached_dump_fn = memcached_return_t function(const memcached_st* ptr,
336     const char* key, size_t key_length, void* context);