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.
13 Common include file for libmemached
16 #ifndef LIBMEMCACHED_COMMON_H
17 #define LIBMEMCACHED_COMMON_H
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
36 #include <netinet/tcp.h>
37 #ifdef TIME_WITH_SYS_TIME
38 # include <sys/time.h>
41 # ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
48 /* Define this here, which will turn on the visibilty controls while we're
49 * building libmemcached.
51 #define BUILDING_LIBMEMCACHED 1
54 #include "libmemcached/memcached.h"
55 #include "libmemcached/memcached_watchpoint.h"
57 /* These are private not to be installed headers */
58 #include "libmemcached/memcached_io.h"
59 #include "libmemcached/memcached_internal.h"
60 #include "libmemcached/libmemcached_probes.h"
61 #include "libmemcached/memcached/protocol_binary.h"
62 #include "libmemcached/byteorder.h"
65 struct memcached_continuum_item_st
{
71 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
73 #define likely(x) if((x))
74 #define unlikely(x) if((x))
78 #define likely(x) if(__builtin_expect((x) != 0, 1))
79 #define unlikely(x) if(__builtin_expect((x) != 0, 0))
83 #define MEMCACHED_BLOCK_SIZE 1024
84 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
85 #define SMALL_STRING_LEN 1024
86 #define HUGE_STRING_LEN 8196
90 MEM_NO_BLOCK
= (1 << 0),
91 MEM_TCP_NODELAY
= (1 << 1),
92 MEM_REUSE_MEMORY
= (1 << 2),
93 MEM_USE_MD5
= (1 << 3),
94 /* 4 was once Ketama */
95 MEM_USE_CRC
= (1 << 5),
96 MEM_USE_CACHE_LOOKUPS
= (1 << 6),
97 MEM_SUPPORT_CAS
= (1 << 7),
98 MEM_BUFFER_REQUESTS
= (1 << 8),
99 MEM_USE_SORT_HOSTS
= (1 << 9),
100 MEM_VERIFY_KEY
= (1 << 10),
101 /* 11 used for weighted ketama */
102 MEM_KETAMA_WEIGHTED
= (1 << 11),
103 MEM_BINARY_PROTOCOL
= (1 << 12),
104 MEM_HASH_WITH_PREFIX_KEY
= (1 << 13),
105 MEM_NOREPLY
= (1 << 14),
106 MEM_USE_UDP
= (1 << 15),
107 MEM_AUTO_EJECT_HOSTS
= (1 << 16),
108 MEM_RANDOMIZE_REPLICA_READ
= (1 << 17)
114 void md5_signature(const unsigned char *key
, unsigned int length
, unsigned char *result
);
116 uint32_t hash_crc32(const char *data
,
118 #ifdef HAVE_HSIEH_HASH
120 uint32_t hsieh_hash(const char *key
, size_t key_length
);
123 uint32_t murmur_hash(const char *key
, size_t key_length
);
125 uint32_t jenkins_hash(const void *key
, size_t length
, uint32_t initval
);
128 memcached_return_t
memcached_connect(memcached_server_st
*ptr
);
130 memcached_return_t
memcached_response(memcached_server_st
*ptr
,
131 char *buffer
, size_t buffer_length
,
132 memcached_result_st
*result
);
134 void memcached_quit_server(memcached_server_st
*ptr
, uint8_t io_death
);
136 #define memcached_server_response_increment(A) (A)->cursor_active++
137 #define memcached_server_response_decrement(A) (A)->cursor_active--
138 #define memcached_server_response_reset(A) (A)->cursor_active=0
141 memcached_return_t
memcached_do(memcached_server_st
*ptr
, const void *commmand
,
142 size_t command_length
, uint8_t with_flush
);
144 memcached_return_t
value_fetch(memcached_server_st
*ptr
,
146 memcached_result_st
*result
);
148 void server_list_free(memcached_st
*ptr
, memcached_server_st
*servers
);
151 memcached_return_t
memcached_key_test(const char * const *keys
,
152 const size_t *key_length
,
153 size_t number_of_keys
);
157 uint32_t generate_hash(memcached_st
*ptr
, const char *key
, size_t key_length
);
160 memcached_return_t
memcached_purge(memcached_server_st
*ptr
);
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 #endif /* LIBMEMCACHED_COMMON_H */