Added option to enable TCP_KEEPALIVE on created sockets.
[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 <netdb.h>
18 #include <netinet/in.h>
19 #include <stdlib.h>
20 #include <sys/types.h>
21
22
23 #if !defined(__cplusplus)
24 # include <stdbool.h>
25 #endif
26
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/server_list.h>
52 #include <libmemcached/storage.h>
53 #include <libmemcached/strerror.h>
54 #include <libmemcached/verbosity.h>
55 #include <libmemcached/version.h>
56
57 struct memcached_st {
58 /**
59 @note these are static and should not change without a call to behavior.
60 */
61 struct {
62 bool is_purging MEMCACHED_BITFIELD;
63 bool is_processing_input MEMCACHED_BITFIELD;
64 } state;
65 struct {
66 // Everything below here is pretty static.
67 bool auto_eject_hosts MEMCACHED_BITFIELD;
68 bool binary_protocol MEMCACHED_BITFIELD;
69 bool buffer_requests MEMCACHED_BITFIELD;
70 bool cork MEMCACHED_BITFIELD;
71 bool hash_with_prefix_key MEMCACHED_BITFIELD;
72 bool ketama_weighted MEMCACHED_BITFIELD;
73 bool no_block MEMCACHED_BITFIELD;
74 bool no_reply MEMCACHED_BITFIELD;
75 bool randomize_replica_read MEMCACHED_BITFIELD;
76 bool reuse_memory MEMCACHED_BITFIELD;
77 bool support_cas MEMCACHED_BITFIELD;
78 bool tcp_nodelay MEMCACHED_BITFIELD;
79 bool use_cache_lookups MEMCACHED_BITFIELD;
80 bool use_sort_hosts MEMCACHED_BITFIELD;
81 bool use_udp MEMCACHED_BITFIELD;
82 bool verify_key MEMCACHED_BITFIELD;
83 bool tcp_keepalive MEMCACHED_BITFIELD;
84 } flags;
85 memcached_server_distribution_t distribution;
86 hashkit_st hashkit;
87 uint32_t continuum_points_counter; // Ketama
88 uint32_t number_of_hosts;
89 memcached_server_st *servers;
90 memcached_server_st *last_disconnected_server;
91 int32_t snd_timeout;
92 int32_t rcv_timeout;
93 uint32_t server_failure_limit;
94 uint32_t io_msg_watermark;
95 uint32_t io_bytes_watermark;
96 uint32_t io_key_prefetch;
97 int cached_errno;
98 int32_t poll_timeout;
99 int32_t connect_timeout;
100 int32_t retry_timeout;
101 uint32_t continuum_count; // Ketama
102 int send_size;
103 int recv_size;
104 void *user_data;
105 time_t next_distribution_rebuild; // Ketama
106 size_t prefix_key_length;
107 uint32_t number_of_replicas;
108 hashkit_st distribution_hashkit;
109 memcached_result_st result;
110 memcached_continuum_item_st *continuum; // Ketama
111
112 struct _allocators_st {
113 memcached_calloc_fn calloc;
114 memcached_free_fn free;
115 memcached_malloc_fn malloc;
116 memcached_realloc_fn realloc;
117 void *context;
118 } allocators;
119
120 memcached_clone_fn on_clone;
121 memcached_cleanup_fn on_cleanup;
122 memcached_trigger_key_fn get_key_failure;
123 memcached_trigger_delete_key_fn delete_trigger;
124 memcached_callback_st *callbacks;
125 char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
126 struct {
127 bool is_allocated MEMCACHED_BITFIELD;
128 } options;
129
130 };
131
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135
136 LIBMEMCACHED_API
137 void memcached_servers_reset(memcached_st *ptr);
138
139 LIBMEMCACHED_API
140 memcached_st *memcached_create(memcached_st *ptr);
141
142 LIBMEMCACHED_API
143 void memcached_free(memcached_st *ptr);
144
145 LIBMEMCACHED_API
146 memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);
147
148 LIBMEMCACHED_API
149 void *memcached_get_user_data(const memcached_st *ptr);
150
151 LIBMEMCACHED_API
152 void *memcached_set_user_data(memcached_st *ptr, void *data);
153
154 LIBMEMCACHED_API
155 memcached_return_t memcached_push(memcached_st *destination, const memcached_st *source);
156
157 LIBMEMCACHED_API
158 memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key);
159
160 LIBMEMCACHED_API
161 uint32_t memcached_server_count(const memcached_st *);
162
163 #ifdef __cplusplus
164 } // extern "C"
165 #endif
166
167
168 #ifdef __cplusplus
169 class Memcached : private memcached_st {
170 public:
171
172 Memcached()
173 {
174 memcached_create(this);
175 }
176
177 ~Memcached()
178 {
179 memcached_free(this);
180 }
181
182 Memcached(const Memcached& source)
183 {
184 memcached_clone(this, &source);
185 }
186
187 Memcached& operator=(const Memcached& source)
188 {
189 memcached_free(this);
190 memcached_clone(this, &source);
191
192 return *this;
193 }
194 };
195 #endif
196
197 #endif /* __LIBMEMCACHED_MEMCACHED_H__ */
198