1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following disclaimer
18 * in the documentation and/or other materials provided with the
21 * * The names of its contributors may not be used to endorse or
22 * promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 Common include file for libmemached
52 #include <sys/types.h>
57 #ifdef TIME_WITH_SYS_TIME
58 # include <sys/time.h>
61 # ifdef HAVE_SYS_TIME_H
62 # include <sys/time.h>
69 #include <libmemcached/memcached.h>
70 #include <libmemcached/watchpoint.h>
71 #include <libmemcached/is.h>
77 typedef struct memcached_server_st
* memcached_server_write_instance_st
;
79 typedef memcached_return_t (*memcached_server_execute_fn
)(memcached_st
*ptr
, memcached_server_write_instance_st server
, void *context
);
82 memcached_server_write_instance_st
memcached_server_instance_fetch(memcached_st
*ptr
, uint32_t server_key
);
85 memcached_return_t
memcached_server_execute(memcached_st
*ptr
,
86 memcached_server_execute_fn callback
,
93 /* These are private not to be installed headers */
94 #include <libmemcached/io.h>
95 #include <libmemcached/do.h>
96 #include <libmemcached/internal.h>
97 #include <libmemcached/array.h>
98 #include <libmemcached/libmemcached_probes.h>
99 #include <libmemcached/memcached/protocol_binary.h>
100 #include <libmemcached/byteorder.h>
101 #include <libmemcached/initialize_query.h>
102 #include <libmemcached/response.h>
103 #include <libmemcached/prefix_key.h>
106 struct memcached_continuum_item_st
112 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
114 #define likely(x) if((x))
115 #define unlikely(x) if((x))
119 #define likely(x) if(__builtin_expect((x) != 0, 1))
120 #define unlikely(x) if(__builtin_expect((x) != 0, 0))
123 #define MEMCACHED_BLOCK_SIZE 1024
124 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
125 #define SMALL_STRING_LEN 1024
126 #define HUGE_STRING_LEN 8196
133 memcached_return_t
memcached_connect(memcached_server_write_instance_st ptr
);
136 memcached_return_t
run_distribution(memcached_st
*ptr
);
138 #define memcached_server_response_increment(A) (A)->cursor_active++
139 #define memcached_server_response_decrement(A) (A)->cursor_active--
140 #define memcached_server_response_reset(A) (A)->cursor_active=0
143 void set_last_disconnected_host(memcached_server_write_instance_st ptr
);
146 memcached_return_t
memcached_key_test(const char * const *keys
,
147 const size_t *key_length
,
148 size_t number_of_keys
);
151 memcached_return_t
memcached_purge(memcached_server_write_instance_st ptr
);
154 memcached_server_st
*memcached_server_create_with(const memcached_st
*memc
,
155 memcached_server_write_instance_st host
,
156 const char *hostname
,
159 memcached_connection_t type
);
162 static inline memcached_return_t
memcached_validate_key_length(size_t key_length
, bool binary
)
164 unlikely (key_length
== 0)
165 return MEMCACHED_BAD_KEY_PROVIDED
;
169 unlikely (key_length
> 0xffff)
170 return MEMCACHED_BAD_KEY_PROVIDED
;
174 unlikely (key_length
>= MEMCACHED_MAX_KEY
)
175 return MEMCACHED_BAD_KEY_PROVIDED
;
178 return MEMCACHED_SUCCESS
;
181 static inline void libmemcached_free(const memcached_st
*ptr
, void *mem
)
183 ptr
->allocators
.free(ptr
, mem
, ptr
->allocators
.context
);
186 static inline void *libmemcached_malloc(const memcached_st
*ptr
, const size_t size
)
188 return ptr
->allocators
.malloc(ptr
, size
, ptr
->allocators
.context
);
191 static inline void *libmemcached_realloc(const memcached_st
*ptr
, void *mem
, const size_t size
)
193 return ptr
->allocators
.realloc(ptr
, mem
, size
, ptr
->allocators
.context
);
196 static inline void *libmemcached_calloc(const memcached_st
*ptr
, size_t nelem
, size_t size
)
198 return ptr
->allocators
.calloc(ptr
, nelem
, size
, ptr
->allocators
.context
);