Style cleanup
[m6w6/libmemcached] / libmemcached / common.h
1 /*
2 Common include file for libmemached
3 */
4
5 #ifndef LIBMEMCACHED_COMMON_H
6 #define LIBMEMCACHED_COMMON_H
7
8 #include "config.h"
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <ctype.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
19 #include <netdb.h>
20 #include <unistd.h>
21 #include <limits.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <sys/un.h>
25 #include <netinet/tcp.h>
26 #ifdef TIME_WITH_SYS_TIME
27 # include <sys/time.h>
28 # include <time.h>
29 #else
30 # ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
32 # else
33 # include <time.h>
34 # endif
35 #endif
36
37 /* Define this here, which will turn on the visibilty controls while we're
38 * building libmemcached.
39 */
40 #define BUILDING_LIBMEMCACHED 1
41
42
43 #include "libmemcached/memcached.h"
44 #include "libmemcached/memcached_watchpoint.h"
45
46 /* These are private not to be installed headers */
47 #include "libmemcached/memcached_io.h"
48 #include "libmemcached/memcached_internal.h"
49 #include "libmemcached/libmemcached_probes.h"
50 #include "libmemcached/memcached/protocol_binary.h"
51 #include "libmemcached/byteorder.h"
52
53 /* string value */
54 struct memcached_continuum_item_st {
55 uint32_t index;
56 uint32_t value;
57 };
58
59
60 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
61
62 #define likely(x) if((x))
63 #define unlikely(x) if((x))
64
65 #else
66
67 #define likely(x) if(__builtin_expect((x) != 0, 1))
68 #define unlikely(x) if(__builtin_expect((x) != 0, 0))
69 #endif
70
71
72 #define MEMCACHED_BLOCK_SIZE 1024
73 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
74 #define SMALL_STRING_LEN 1024
75 #define HUGE_STRING_LEN 8196
76
77
78 typedef enum {
79 MEM_NO_BLOCK= (1 << 0),
80 MEM_TCP_NODELAY= (1 << 1),
81 MEM_REUSE_MEMORY= (1 << 2),
82 MEM_USE_MD5= (1 << 3),
83 /* 4 was once Ketama */
84 MEM_USE_CRC= (1 << 5),
85 MEM_USE_CACHE_LOOKUPS= (1 << 6),
86 MEM_SUPPORT_CAS= (1 << 7),
87 MEM_BUFFER_REQUESTS= (1 << 8),
88 MEM_USE_SORT_HOSTS= (1 << 9),
89 MEM_VERIFY_KEY= (1 << 10),
90 /* 11 used for weighted ketama */
91 MEM_KETAMA_WEIGHTED= (1 << 11),
92 MEM_BINARY_PROTOCOL= (1 << 12),
93 MEM_HASH_WITH_PREFIX_KEY= (1 << 13),
94 MEM_NOREPLY= (1 << 14),
95 MEM_USE_UDP= (1 << 15),
96 MEM_AUTO_EJECT_HOSTS= (1 << 16),
97 MEM_RANDOMIZE_REPLICA_READ= (1 << 17)
98 } memcached_flags;
99
100 /* Hashing algo */
101
102 LIBMEMCACHED_LOCAL
103 void md5_signature(const unsigned char *key, unsigned int length, unsigned char *result);
104 LIBMEMCACHED_LOCAL
105 uint32_t hash_crc32(const char *data,
106 size_t data_len);
107 #ifdef HAVE_HSIEH_HASH
108 LIBMEMCACHED_LOCAL
109 uint32_t hsieh_hash(const char *key, size_t key_length);
110 #endif
111 LIBMEMCACHED_LOCAL
112 uint32_t murmur_hash(const char *key, size_t key_length);
113 LIBMEMCACHED_LOCAL
114 uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval);
115
116 LIBMEMCACHED_LOCAL
117 memcached_return_t memcached_connect(memcached_server_st *ptr);
118 LIBMEMCACHED_LOCAL
119 memcached_return_t memcached_response(memcached_server_st *ptr,
120 char *buffer, size_t buffer_length,
121 memcached_result_st *result);
122 LIBMEMCACHED_LOCAL
123 void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death);
124
125 #define memcached_server_response_increment(A) (A)->cursor_active++
126 #define memcached_server_response_decrement(A) (A)->cursor_active--
127 #define memcached_server_response_reset(A) (A)->cursor_active=0
128
129 LIBMEMCACHED_LOCAL
130 memcached_return_t memcached_do(memcached_server_st *ptr, const void *commmand,
131 size_t command_length, uint8_t with_flush);
132 LIBMEMCACHED_LOCAL
133 memcached_return_t value_fetch(memcached_server_st *ptr,
134 char *buffer,
135 memcached_result_st *result);
136 LIBMEMCACHED_LOCAL
137 void server_list_free(memcached_st *ptr, memcached_server_st *servers);
138
139 LIBMEMCACHED_LOCAL
140 memcached_return_t memcached_key_test(const char * const *keys,
141 const size_t *key_length,
142 size_t number_of_keys);
143
144
145 LIBMEMCACHED_LOCAL
146 uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length);
147
148 LIBMEMCACHED_LOCAL
149 memcached_return_t memcached_purge(memcached_server_st *ptr);
150
151 static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary)
152 {
153 unlikely (key_length == 0)
154 return MEMCACHED_BAD_KEY_PROVIDED;
155
156 if (binary)
157 {
158 unlikely (key_length > 0xffff)
159 return MEMCACHED_BAD_KEY_PROVIDED;
160 }
161 else
162 {
163 unlikely (key_length >= MEMCACHED_MAX_KEY)
164 return MEMCACHED_BAD_KEY_PROVIDED;
165 }
166
167 return MEMCACHED_SUCCESS;
168 }
169
170 #endif /* LIBMEMCACHED_COMMON_H */