eea5319b654c800dcecd20cbe867b67d65ae3db0
[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 # include <ciso646>
30 #else
31 # include <stddef.h>
32 # include <stdio.h>
33 # include <stdlib.h>
34 # include <string.h>
35 # include <time.h>
36 # include <errno.h>
37 # include <limits.h>
38 # include <iso646.h>
39 #endif
40
41 #ifdef HAVE_SYS_UN_H
42 # include <sys/un.h>
43 #endif
44
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
47 #endif
48
49 #include <fcntl.h>
50 #include <sys/types.h>
51
52 #ifdef HAVE_UNISTD_H
53 # include <unistd.h>
54 #endif
55
56 #ifdef HAVE_SYS_SOCKET_H
57 # include <sys/socket.h>
58 #endif
59
60 #ifdef HAVE_STRINGS_H
61 # include <strings.h>
62 #endif
63
64 #ifdef HAVE_DLFCN_H
65 # include <dlfcn.h>
66 #endif
67
68 #if defined(_WIN32)
69 # include "libmemcached/windows.hpp"
70 #endif
71
72 #include "libmemcached-1.0/memcached.h"
73 #include "libmemcached/watchpoint.h"
74 #include "libmemcached/is.h"
75 typedef struct memcached_st Memcached;
76
77 #include "libmemcached/poll.h"
78
79 #ifdef __cplusplus
80 memcached_instance_st *memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
81 #endif
82
83 /* These are private not to be installed headers */
84 #include "libmemcached/error.hpp"
85 #include "libmemcached/memory.h"
86 #include "libmemcached/io.h"
87 #ifdef __cplusplus
88 # include "libmemcached/string.hpp"
89 # include "libmemcachedprotocol-0.0/binary.h"
90 # include "libmemcached/io.hpp"
91 # include "libmemcached/udp.hpp"
92 # include "libmemcached/do.hpp"
93 # include "libmemcached/socket.hpp"
94 # include "libmemcached/connect.hpp"
95 # include "libmemcached/allocators.hpp"
96 # include "libmemcached/hash.hpp"
97 # include "libmemcached/quit.hpp"
98 # include "libmemcached/instance.hpp"
99 # include "libmemcached/server_instance.h"
100 # include "libmemcached/server.hpp"
101 # include "libmemcached/flag.hpp"
102 # include "libmemcached/behavior.hpp"
103 # include "libmemcached/sasl.hpp"
104 # include "libmemcached/server_list.hpp"
105 #endif
106
107 #include "libmemcached/internal.h"
108 #include "libmemcached/array.h"
109 #include "libmemcached/libmemcached_probes.h"
110 #include "libmemcached/byteorder.h"
111 #include "libmemcached/initialize_query.h"
112
113 #ifdef __cplusplus
114 # include "libmemcached/response.h"
115 # include "libmemcached/namespace.h"
116 #else
117 # include "libmemcached/virtual_bucket.h"
118 #endif
119
120 #ifdef __cplusplus
121 # include "libmemcached/backtrace.hpp"
122 # include "libmemcached/assert.hpp"
123 # include "libmemcached/server.hpp"
124 # include "libmemcached/key.hpp"
125 # include "libmemcached/result.h"
126 # include "libmemcached/version.hpp"
127 #endif
128
129 #include "libmemcached/continuum.hpp"
130
131 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
132
133 # define likely(x) if ((x))
134 # define unlikely(x) if ((x))
135
136 #else
137
138 # define likely(x) if (__builtin_expect((x) != 0, 1))
139 # define unlikely(x) if (__builtin_expect((x) != 0, 0))
140 #endif
141
142 #define MEMCACHED_BLOCK_SIZE 1024
143 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
144 #define SMALL_STRING_LEN 1024
145 #define HUGE_STRING_LEN 8196
146
147 #ifdef __cplusplus
148 extern "C" {
149 #endif
150
151 memcached_return_t run_distribution(memcached_st *ptr);
152
153 #ifdef __cplusplus
154 static inline void memcached_server_response_increment(memcached_instance_st *instance) {
155 instance->events(POLLIN);
156 instance->cursor_active_++;
157 }
158 #endif
159
160 #define memcached_server_response_decrement(A) (A)->cursor_active_--
161 #define memcached_server_response_reset(A) (A)->cursor_active_ = 0
162
163 #define memcached_instance_response_increment(A) (A)->cursor_active_++
164 #define memcached_instance_response_decrement(A) (A)->cursor_active_--
165 #define memcached_instance_response_reset(A) (A)->cursor_active_ = 0
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #ifdef __cplusplus
172 bool memcached_purge(memcached_instance_st *);
173 memcached_instance_st *memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key);
174 #endif