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