4b025fb368c2d6de8181fb63eeb4655846148fce
[m6w6/libmemcached] / src / libmemcached / common.h
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #include "mem_config.h"
19
20 #ifdef __cplusplus
21 # include <cstddef>
22 # include <cstdio>
23 # include <cstdlib>
24 # include <cstring>
25 # include <ctime>
26 # include <cctype>
27 # include <cerrno>
28 # include <climits>
29 #else
30 # ifdef HAVE_STDDEF_H
31 # include <stddef.h>
32 # endif
33 # ifdef HAVE_STDLIB_H
34 # include <stdio.h>
35 # endif
36 # ifdef HAVE_STDLIB_H
37 # include <stdlib.h>
38 # endif
39 # include <string.h>
40 # ifdef HAVE_TIME_H
41 # include <time.h>
42 # endif
43 # ifdef HAVE_ERRNO_H
44 # include <errno.h>
45 # endif
46 # ifdef HAVE_LIMITS_H
47 # include <limits.h>
48 # endif
49 #endif
50
51 #ifdef HAVE_SYS_UN_H
52 # include <sys/un.h>
53 #endif
54
55 #ifdef HAVE_SYS_TIME_H
56 # include <sys/time.h>
57 #endif
58
59 #ifdef HAVE_FCNTL_H
60 # include <fcntl.h>
61 #endif
62
63 #ifdef HAVE_SYS_TYPES_H
64 # include <sys/types.h>
65 #endif
66
67 #ifdef HAVE_UNISTD_H
68 # include <unistd.h>
69 #endif
70
71 #ifdef HAVE_SYS_SOCKET_H
72 # include <sys/socket.h>
73 #endif
74
75 #ifdef HAVE_STRINGS_H
76 # include <strings.h>
77 #endif
78
79 #ifdef HAVE_DLFCN_H
80 # include <dlfcn.h>
81 #endif
82
83 #if defined(_WIN32)
84 # include "libmemcached/windows.hpp"
85 #endif
86
87 #include "libmemcached-1.0/memcached.h"
88 #include "libmemcached/watchpoint.h"
89 #include "libmemcached/is.h"
90 typedef struct memcached_st Memcached;
91
92 #ifdef HAVE_POLL_H
93 # include <poll.h>
94 #else
95 # include "libmemcached/poll.h"
96 #endif
97
98 #ifdef __cplusplus
99 memcached_instance_st *memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
100 #endif
101
102 /* These are private not to be installed headers */
103 #include "libmemcached/error.hpp"
104 #include "libmemcached/memory.h"
105 #include "libmemcached/io.h"
106 #ifdef __cplusplus
107 # include "libmemcached/string.hpp"
108 # include "libmemcachedprotocol-0.0/binary.h"
109 # include "libmemcached/io.hpp"
110 # include "libmemcached/udp.hpp"
111 # include "libmemcached/do.hpp"
112 # include "libmemcached/socket.hpp"
113 # include "libmemcached/connect.hpp"
114 # include "libmemcached/allocators.hpp"
115 # include "libmemcached/hash.hpp"
116 # include "libmemcached/quit.hpp"
117 # include "libmemcached/instance.hpp"
118 # include "libmemcached/server_instance.h"
119 # include "libmemcached/server.hpp"
120 # include "libmemcached/flag.hpp"
121 # include "libmemcached/behavior.hpp"
122 # include "libmemcached/sasl.hpp"
123 # include "libmemcached/server_list.hpp"
124 #endif
125
126 #include "libmemcached/internal.h"
127 #include "libmemcached/array.h"
128 #include "libmemcached/libmemcached_probes.h"
129 #include "libmemcached/byteorder.h"
130 #include "libmemcached/initialize_query.h"
131
132 #ifdef __cplusplus
133 # include "libmemcached/response.h"
134 # include "libmemcached/namespace.h"
135 #else
136 # include "libmemcached/virtual_bucket.h"
137 #endif
138
139 #ifdef __cplusplus
140 # include "libmemcached/backtrace.hpp"
141 # include "libmemcached/assert.hpp"
142 # include "libmemcached/server.hpp"
143 # include "libmemcached/key.hpp"
144 # include "libmemcached/result.h"
145 # include "libmemcached/version.hpp"
146 #endif
147
148 #include "libmemcached/continuum.hpp"
149
150 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
151
152 # define likely(x) if ((x))
153 # define unlikely(x) if ((x))
154
155 #else
156
157 # define likely(x) if (__builtin_expect((x) != 0, 1))
158 # define unlikely(x) if (__builtin_expect((x) != 0, 0))
159 #endif
160
161 #define MEMCACHED_BLOCK_SIZE 1024
162 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
163 #define SMALL_STRING_LEN 1024
164 #define HUGE_STRING_LEN 8196
165
166 #ifdef __cplusplus
167 extern "C" {
168 #endif
169
170 memcached_return_t run_distribution(memcached_st *ptr);
171
172 #ifdef __cplusplus
173 static inline void memcached_server_response_increment(memcached_instance_st *instance) {
174 instance->events(POLLIN);
175 instance->cursor_active_++;
176 }
177 #endif
178
179 #define memcached_server_response_decrement(A) (A)->cursor_active_--
180 #define memcached_server_response_reset(A) (A)->cursor_active_ = 0
181
182 #define memcached_instance_response_increment(A) (A)->cursor_active_++
183 #define memcached_instance_response_decrement(A) (A)->cursor_active_--
184 #define memcached_instance_response_reset(A) (A)->cursor_active_ = 0
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #ifdef __cplusplus
191 bool memcached_purge(memcached_instance_st *);
192 memcached_instance_st *memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key);
193 #endif