Merge in autoconf/libtest updates.
[m6w6/libmemcached] / libmemcached / common.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * LibMemcached
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * Copyright (C) 2006-2009 Brian Aker
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
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
19 * distribution.
20 *
21 * * The names of its contributors may not be used to endorse or
22 * promote products derived from this software without specific prior
23 * written permission.
24 *
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.
36 *
37 */
38
39 /*
40 Common include file for libmemached
41 */
42
43 #pragma once
44
45 #include <config.h>
46
47 #ifdef __cplusplus
48 #include <cstdio>
49 #include <cstdlib>
50 #include <cstring>
51 #include <ctime>
52 #include <ctype.h>
53 #else
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <time.h>
58 #endif
59
60 #include <errno.h>
61 #include <fcntl.h>
62 #include <limits.h>
63 #include <sys/types.h>
64 #include <unistd.h>
65
66 #include <libmemcached/memcached.h>
67 #include <libmemcached/watchpoint.h>
68 #include <libmemcached/is.h>
69 #include <libmemcached/namespace.h>
70
71 #include <libmemcached/server_instance.h>
72
73 #ifdef HAVE_POLL_H
74 #include <poll.h>
75 #else
76 #include "poll/poll.h"
77 #endif
78
79
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83
84 typedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);
85
86 LIBMEMCACHED_LOCAL
87 memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key);
88
89 LIBMEMCACHED_LOCAL
90 memcached_return_t memcached_server_execute(memcached_st *ptr,
91 memcached_server_execute_fn callback,
92 void *context);
93 #ifdef __cplusplus
94 } // extern "C"
95 #endif
96
97
98 /* These are private not to be installed headers */
99 #include <libmemcached/error.hpp>
100 #include <libmemcached/memory.h>
101 #include <libmemcached/io.h>
102 #ifdef __cplusplus
103 #include <libmemcached/string.hpp>
104 #include <libmemcached/io.hpp>
105 #include <libmemcached/do.hpp>
106 #endif
107 #include <libmemcached/internal.h>
108 #include <libmemcached/array.h>
109 #include <libmemcached/libmemcached_probes.h>
110 #include <libmemcached/memcached/protocol_binary.h>
111 #include <libmemcached/byteorder.h>
112 #include <libmemcached/initialize_query.h>
113 #include <libmemcached/response.h>
114 #include <libmemcached/namespace.h>
115
116 #ifdef __cplusplus
117 #include <libmemcached/backtrace.hpp>
118 #include <libmemcached/assert.hpp>
119 #endif
120
121 #include <libmemcached/continuum.hpp>
122
123 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
124
125 #define likely(x) if((x))
126 #define unlikely(x) if((x))
127
128 #else
129
130 #define likely(x) if(__builtin_expect((x) != 0, 1))
131 #define unlikely(x) if(__builtin_expect((x) != 0, 0))
132 #endif
133
134 #define MEMCACHED_BLOCK_SIZE 1024
135 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
136 #define SMALL_STRING_LEN 1024
137 #define HUGE_STRING_LEN 8196
138
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142
143 LIBMEMCACHED_LOCAL
144 memcached_return_t memcached_connect(memcached_server_write_instance_st ptr);
145
146 LIBMEMCACHED_LOCAL
147 memcached_return_t run_distribution(memcached_st *ptr);
148
149 #define memcached_server_response_increment(A) (A)->cursor_active++
150 #define memcached_server_response_decrement(A) (A)->cursor_active--
151 #define memcached_server_response_reset(A) (A)->cursor_active=0
152
153 LIBMEMCACHED_LOCAL
154 void set_last_disconnected_host(memcached_server_write_instance_st ptr);
155
156 #ifdef __cplusplus
157 LIBMEMCACHED_LOCAL
158 memcached_return_t memcached_key_test(const memcached_st& memc,
159 const char * const *keys,
160 const size_t *key_length,
161 size_t number_of_keys);
162 #endif
163
164 LIBMEMCACHED_LOCAL
165 memcached_return_t memcached_purge(memcached_server_write_instance_st ptr);
166
167 LIBMEMCACHED_LOCAL
168 memcached_server_st *__server_create_with(const memcached_st *memc,
169 memcached_server_write_instance_st host,
170 const char *hostname,
171 in_port_t port,
172 uint32_t weight,
173 memcached_connection_t type);
174
175
176 static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary)
177 {
178 if (key_length == 0)
179 {
180 return MEMCACHED_BAD_KEY_PROVIDED;
181 }
182
183 if (binary)
184 {
185 if (key_length > 0xffff)
186 {
187 return MEMCACHED_BAD_KEY_PROVIDED;
188 }
189 }
190 else
191 {
192 if (key_length >= MEMCACHED_MAX_KEY)
193 {
194 return MEMCACHED_BAD_KEY_PROVIDED;
195 }
196 }
197
198 return MEMCACHED_SUCCESS;
199 }
200
201 #ifdef __cplusplus
202 }
203 #endif