2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: interface for memcached server
9 * Description: main include file for libmemcached
13 #ifndef __LIBMEMCACHED_MEMCACHED_H__
14 #define __LIBMEMCACHED_MEMCACHED_H__
18 #include <netinet/in.h>
20 #include <sys/types.h>
23 #if !defined(__cplusplus)
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/storage.h>
52 #include <libmemcached/strerror.h>
53 #include <libmemcached/verbosity.h>
54 #include <libmemcached/version.h>
58 @note these are static and should not change without a call to behavior.
62 bool is_processing_input
:1;
65 // Everything below here is pretty static.
66 bool auto_eject_hosts
:1;
67 bool binary_protocol
:1;
68 bool buffer_requests
:1;
70 bool hash_with_prefix_key
:1;
71 bool ketama_weighted
:1;
74 bool randomize_replica_read
:1;
78 bool use_cache_lookups
:1;
79 bool use_sort_hosts
:1;
83 memcached_server_distribution_t distribution
;
85 uint32_t continuum_points_counter
; // Ketama
86 uint32_t number_of_hosts
;
87 memcached_server_st
*servers
;
88 memcached_server_st
*last_disconnected_server
;
91 uint32_t server_failure_limit
;
92 uint32_t io_msg_watermark
;
93 uint32_t io_bytes_watermark
;
94 uint32_t io_key_prefetch
;
97 int32_t connect_timeout
;
98 int32_t retry_timeout
;
99 uint32_t continuum_count
; // Ketama
103 time_t next_distribution_rebuild
; // Ketama
104 size_t prefix_key_length
;
105 uint32_t number_of_replicas
;
106 hashkit_st distribution_hashkit
;
107 memcached_result_st result
;
108 memcached_continuum_item_st
*continuum
; // Ketama
110 struct _allocators_st
{
111 memcached_calloc_fn calloc
;
112 memcached_free_fn free
;
113 memcached_malloc_fn malloc
;
114 memcached_realloc_fn realloc
;
118 memcached_clone_fn on_clone
;
119 memcached_cleanup_fn on_cleanup
;
120 memcached_trigger_key_fn get_key_failure
;
121 memcached_trigger_delete_key_fn delete_trigger
;
122 memcached_callback_st
*callbacks
;
123 char prefix_key
[MEMCACHED_PREFIX_KEY_MAX_SIZE
];
135 void memcached_servers_reset(memcached_st
*ptr
);
138 memcached_st
*memcached_create(memcached_st
*ptr
);
141 void memcached_free(memcached_st
*ptr
);
144 memcached_st
*memcached_clone(memcached_st
*clone
, const memcached_st
*ptr
);
147 void *memcached_get_user_data(const memcached_st
*ptr
);
150 void *memcached_set_user_data(memcached_st
*ptr
, void *data
);
158 static inline memcached_server_st
*memcached_server_instance_fetch(memcached_st
*ptr
, uint32_t server_key
)
160 return &ptr
->servers
[server_key
];
164 class Memcached
: private memcached_st
{
169 memcached_create(this);
174 memcached_free(this);
177 Memcached(const Memcached
& source
)
179 memcached_clone(this, &source
);
182 Memcached
& operator=(const Memcached
& source
)
184 memcached_free(this);
185 memcached_clone(this, &source
);
192 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */