1 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2  * 
3  *  Libmemcached library
4  *
5  *  Copyright (C) 2011 Data Differential, http://datadifferential.com/ 
6  *  All rights reserved.
7  *
8  *  Redistribution and use in source and binary forms, with or without
9  *  modification, are permitted provided that the following conditions are
10  *  met:
11  *
12  *      * Redistributions of source code must retain the above copyright
13  *  notice, this list of conditions and the following disclaimer.
14  *
15  *      * Redistributions in binary form must reproduce the above
16  *  copyright notice, this list of conditions and the following disclaimer
17  *  in the documentation and/or other materials provided with the
18  *  distribution.
19  *
20  *      * The names of its contributors may not be used to endorse or
21  *  promote products derived from this software without specific prior
22  *  written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 module memcache.types;
38 
39 version (windows)
40 {
41 
42     public import std.c.windows.winsock;
43 
44     alias int in_port_t;
45 
46     alias SOCKET memcached_socket_t;
47 
48 }
49 else
50 {
51     alias int memcached_socket_t;
52 
53 }
54 
55 auto memcached_size(T)()
56 {
57     return T.size;
58 }
59 
60 auto memcached_c_str(T)()
61 {
62     return X.c_str;
63 }
64 
65 extern (C):
66 
67 enum memcached_behavior_t
68 {
69     MEMCACHED_BEHAVIOR_NO_BLOCK,
70     MEMCACHED_BEHAVIOR_TCP_NODELAY,
71     MEMCACHED_BEHAVIOR_HASH,
72     MEMCACHED_BEHAVIOR_KETAMA,
73     MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE,
74     MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE,
75     MEMCACHED_BEHAVIOR_CACHE_LOOKUPS,
76     MEMCACHED_BEHAVIOR_SUPPORT_CAS,
77     MEMCACHED_BEHAVIOR_POLL_TIMEOUT,
78     MEMCACHED_BEHAVIOR_DISTRIBUTION,
79     MEMCACHED_BEHAVIOR_BUFFER_REQUESTS,
80     MEMCACHED_BEHAVIOR_USER_DATA,
81     MEMCACHED_BEHAVIOR_SORT_HOSTS,
82     MEMCACHED_BEHAVIOR_VERIFY_KEY,
83     MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT,
84     MEMCACHED_BEHAVIOR_RETRY_TIMEOUT,
85     MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED,
86     MEMCACHED_BEHAVIOR_KETAMA_HASH,
87     MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
88     MEMCACHED_BEHAVIOR_SND_TIMEOUT,
89     MEMCACHED_BEHAVIOR_RCV_TIMEOUT,
90     MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT,
91     MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK,
92     MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK,
93     MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH,
94     MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY,
95     MEMCACHED_BEHAVIOR_NOREPLY,
96     MEMCACHED_BEHAVIOR_USE_UDP,
97     MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS,
98     MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS,
99     MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ,
100     MEMCACHED_BEHAVIOR_CORK,
101     MEMCACHED_BEHAVIOR_TCP_KEEPALIVE,
102     MEMCACHED_BEHAVIOR_TCP_KEEPIDLE,
103     MEMCACHED_BEHAVIOR_LOAD_FROM_FILE,
104     MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS,
105     MEMCACHED_BEHAVIOR_DEAD_TIMEOUT,
106     MEMCACHED_BEHAVIOR_SERVER_TIMEOUT_LIMIT,
107     MEMCACHED_BEHAVIOR_MAX
108 };
109 
110 enum memcached_callback_t
111 {
112     MEMCACHED_CALLBACK_PREFIX_KEY = 0,
113     MEMCACHED_CALLBACK_USER_DATA = 1,
114     MEMCACHED_CALLBACK_CLEANUP_FUNCTION = 2,
115     MEMCACHED_CALLBACK_CLONE_FUNCTION = 3,
116     MEMCACHED_CALLBACK_GET_FAILURE = 7,
117     MEMCACHED_CALLBACK_DELETE_TRIGGER = 8,
118     MEMCACHED_CALLBACK_MAX,
119     MEMCACHED_CALLBACK_NAMESPACE = MEMCACHED_CALLBACK_PREFIX_KEY
120 };
121 
122 enum memcached_connection_t : int
123 {
124     MEMCACHED_CONNECTION_TCP,
125     MEMCACHED_CONNECTION_UDP,
126     MEMCACHED_CONNECTION_UNIX_SOCKET
127 };
128 
129 enum memcached_return_t : int
130 {
131     MEMCACHED_SUCCESS,
132     MEMCACHED_FAILURE,
133     MEMCACHED_HOST_LOOKUP_FAILURE, // getaddrinfo() and getnameinfo() only
134     MEMCACHED_CONNECTION_FAILURE,
135     MEMCACHED_CONNECTION_BIND_FAILURE, // DEPRECATED, see MEMCACHED_HOST_LOOKUP_FAILURE
136     MEMCACHED_WRITE_FAILURE,
137     MEMCACHED_READ_FAILURE,
138     MEMCACHED_UNKNOWN_READ_FAILURE,
139     MEMCACHED_PROTOCOL_ERROR,
140     MEMCACHED_CLIENT_ERROR,
141     MEMCACHED_SERVER_ERROR, // Server returns "SERVER_ERROR"
142     MEMCACHED_ERROR, // Server returns "ERROR"
143     MEMCACHED_DATA_EXISTS,
144     MEMCACHED_DATA_DOES_NOT_EXIST,
145     MEMCACHED_NOTSTORED,
146     MEMCACHED_STORED,
147     MEMCACHED_NOTFOUND,
148     MEMCACHED_MEMORY_ALLOCATION_FAILURE,
149     MEMCACHED_PARTIAL_READ,
150     MEMCACHED_SOME_ERRORS,
151     MEMCACHED_NO_SERVERS,
152     MEMCACHED_END,
153     MEMCACHED_DELETED,
154     MEMCACHED_VALUE,
155     MEMCACHED_STAT,
156     MEMCACHED_ITEM,
157     MEMCACHED_ERRNO,
158     MEMCACHED_FAIL_UNIX_SOCKET, // DEPRECATED
159     MEMCACHED_NOT_SUPPORTED,
160     MEMCACHED_NO_KEY_PROVIDED, /* Deprecated. Use MEMCACHED_BAD_KEY_PROVIDED! */
161         MEMCACHED_FETCH_NOTFINISHED, MEMCACHED_TIMEOUT, MEMCACHED_BUFFERED,
162         MEMCACHED_BAD_KEY_PROVIDED, MEMCACHED_INVALID_HOST_PROTOCOL,
163         MEMCACHED_SERVER_MARKED_DEAD, MEMCACHED_UNKNOWN_STAT_KEY,
164         MEMCACHED_E2BIG, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_KEY_TOO_BIG,
165         MEMCACHED_AUTH_PROBLEM, MEMCACHED_AUTH_FAILURE,
166         MEMCACHED_AUTH_CONTINUE, MEMCACHED_PARSE_ERROR,
167         MEMCACHED_PARSE_USER_ERROR, MEMCACHED_DEPRECATED,
168         MEMCACHED_IN_PROGRESS, MEMCACHED_SERVER_TEMPORARILY_DISABLED,
169         MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE, MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */
170         MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE = MEMCACHED_ERROR
171 };
172 
173 enum memcached_hash_t
174 {
175     MEMCACHED_HASH_DEFAULT = 0,
176     MEMCACHED_HASH_MD5,
177     MEMCACHED_HASH_CRC,
178     MEMCACHED_HASH_FNV1_64,
179     MEMCACHED_HASH_FNV1A_64,
180     MEMCACHED_HASH_FNV1_32,
181     MEMCACHED_HASH_FNV1A_32,
182     MEMCACHED_HASH_HSIEH,
183     MEMCACHED_HASH_MURMUR,
184     MEMCACHED_HASH_JENKINS,
185     MEMCACHED_HASH_MURMUR3,
186     MEMCACHED_HASH_CUSTOM,
187     MEMCACHED_HASH_MAX
188 };
189 
190 //basic_string.d
191 struct memcached_string_t
192 {
193     const char* c_str;
194     size_t size;
195 };
196 
197 //server.h
198 enum memcached_server_state_t
199 {
200     MEMCACHED_SERVER_STATE_NEW, // fd == -1, no address lookup has been done
201     MEMCACHED_SERVER_STATE_ADDRINFO, // ADDRRESS information has been gathered
202     MEMCACHED_SERVER_STATE_IN_PROGRESS,
203     MEMCACHED_SERVER_STATE_CONNECTED,
204     MEMCACHED_SERVER_STATE_IN_TIMEOUT,
205     MEMCACHED_SERVER_STATE_DISABLED
206 };
207 
208 //server_distribution.h
209 enum memcached_server_distribution_t
210 {
211     MEMCACHED_DISTRIBUTION_MODULA,
212     MEMCACHED_DISTRIBUTION_CONSISTENT,
213     MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA,
214     MEMCACHED_DISTRIBUTION_RANDOM,
215     MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY,
216     MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED,
217     MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET,
218     MEMCACHED_DISTRIBUTION_CONSISTENT_MAX
219 };