defb3b0da19b31ab7b79662e3d6e5c2bc9111dd3
[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 #include "libmemcached-1.0/memcached.h"
69 #include "libmemcached/watchpoint.h"
70 #include "libmemcached/is.h"
71 typedef struct memcached_st Memcached;
72
73 #ifdef __cplusplus
74 memcached_instance_st *memcached_instance_fetch(memcached_st *ptr, uint32_t server_key);
75 #endif
76
77 /* These are private not to be installed headers */
78 #include "libmemcached/error.hpp"
79 #include "libmemcached/memory.h"
80 #include "libmemcached/io.h"
81 #ifdef __cplusplus
82 # include "libmemcached/string.hpp"
83 # include "libmemcachedprotocol-0.0/binary.h"
84 # include "libmemcached/io.hpp"
85 # include "libmemcached/udp.hpp"
86 # include "libmemcached/do.hpp"
87 # include "libmemcached/connect.hpp"
88 # include "libmemcached/allocators.hpp"
89 # include "libmemcached/hash.hpp"
90 # include "libmemcached/quit.hpp"
91 # include "libmemcached/instance.hpp"
92 # include "libmemcached/server_instance.h"
93 # include "libmemcached/server.hpp"
94 # include "libmemcached/flag.hpp"
95 # include "libmemcached/behavior.hpp"
96 # include "libmemcached/sasl.hpp"
97 # include "libmemcached/server_list.hpp"
98 #endif
99
100 #include "libmemcached/internal.h"
101 #include "libmemcached/array.h"
102 #include "libmemcached/libmemcached_probes.h"
103 #include "libmemcached/byteorder.h"
104 #include "libmemcached/initialize_query.h"
105
106 #ifdef __cplusplus
107 # include "libmemcached/response.h"
108 # include "libmemcached/namespace.h"
109 #else
110 # include "libmemcached/virtual_bucket.h"
111 #endif
112
113 #ifdef __cplusplus
114 # include "libmemcached/backtrace.hpp"
115 # include "libmemcached/assert.hpp"
116 # include "libmemcached/server.hpp"
117 # include "libmemcached/key.hpp"
118 # include "libmemcached/result.h"
119 # include "libmemcached/version.hpp"
120 #endif
121
122 #include "libmemcached/continuum.hpp"
123
124 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
125
126 # define likely(x) if ((x))
127 # define unlikely(x) if ((x))
128
129 #else
130
131 # define likely(x) if (__builtin_expect((x) != 0, 1))
132 # define unlikely(x) if (__builtin_expect((x) != 0, 0))
133 #endif
134
135 #define MEMCACHED_BLOCK_SIZE 1024
136 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
137 #define SMALL_STRING_LEN 1024
138 #define HUGE_STRING_LEN 8196
139
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143
144 memcached_return_t run_distribution(memcached_st *ptr);
145
146 #ifdef __cplusplus
147 # include "p9y/poll.hpp"
148 static inline void memcached_server_response_increment(memcached_instance_st *instance) {
149 instance->events(POLLIN);
150 instance->cursor_active_++;
151 }
152 #endif
153
154 #define memcached_server_response_decrement(A) (A)->cursor_active_--
155 #define memcached_server_response_reset(A) (A)->cursor_active_ = 0
156
157 #define memcached_instance_response_increment(A) (A)->cursor_active_++
158 #define memcached_instance_response_decrement(A) (A)->cursor_active_--
159 #define memcached_instance_response_reset(A) (A)->cursor_active_ = 0
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165 #ifdef __cplusplus
166 bool memcached_purge(memcached_instance_st *);
167 memcached_instance_st *memcached_instance_by_position(const memcached_st *ptr, uint32_t server_key);
168 #endif