fa36243f769db098cb474392384c6ba6c3d200d1
[awesomized/libmemcached] / libmemcached / return.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached library
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37 #pragma once
38
39 enum memcached_return_t {
40 MEMCACHED_SUCCESS,
41 MEMCACHED_FAILURE,
42 MEMCACHED_HOST_LOOKUP_FAILURE, // getaddrinfo() and getnameinfo() only
43 MEMCACHED_CONNECTION_FAILURE,
44 MEMCACHED_CONNECTION_BIND_FAILURE, // DEPRECATED, see MEMCACHED_HOST_LOOKUP_FAILURE
45 MEMCACHED_WRITE_FAILURE,
46 MEMCACHED_READ_FAILURE,
47 MEMCACHED_UNKNOWN_READ_FAILURE,
48 MEMCACHED_PROTOCOL_ERROR,
49 MEMCACHED_CLIENT_ERROR,
50 MEMCACHED_SERVER_ERROR,
51 MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE, // DEPRECATED
52 MEMCACHED_DATA_EXISTS,
53 MEMCACHED_DATA_DOES_NOT_EXIST,
54 MEMCACHED_NOTSTORED,
55 MEMCACHED_STORED,
56 MEMCACHED_NOTFOUND,
57 MEMCACHED_MEMORY_ALLOCATION_FAILURE,
58 MEMCACHED_PARTIAL_READ,
59 MEMCACHED_SOME_ERRORS,
60 MEMCACHED_NO_SERVERS,
61 MEMCACHED_END,
62 MEMCACHED_DELETED,
63 MEMCACHED_VALUE,
64 MEMCACHED_STAT,
65 MEMCACHED_ITEM,
66 MEMCACHED_ERRNO,
67 MEMCACHED_FAIL_UNIX_SOCKET, // DEPRECATED
68 MEMCACHED_NOT_SUPPORTED,
69 MEMCACHED_NO_KEY_PROVIDED, /* Deprecated. Use MEMCACHED_BAD_KEY_PROVIDED! */
70 MEMCACHED_FETCH_NOTFINISHED,
71 MEMCACHED_TIMEOUT,
72 MEMCACHED_BUFFERED,
73 MEMCACHED_BAD_KEY_PROVIDED,
74 MEMCACHED_INVALID_HOST_PROTOCOL,
75 MEMCACHED_SERVER_MARKED_DEAD,
76 MEMCACHED_UNKNOWN_STAT_KEY,
77 MEMCACHED_E2BIG,
78 MEMCACHED_INVALID_ARGUMENTS,
79 MEMCACHED_KEY_TOO_BIG,
80 MEMCACHED_AUTH_PROBLEM,
81 MEMCACHED_AUTH_FAILURE,
82 MEMCACHED_AUTH_CONTINUE,
83 MEMCACHED_PARSE_ERROR,
84 MEMCACHED_PARSE_USER_ERROR,
85 MEMCACHED_DEPRECATED,
86 MEMCACHED_IN_PROGRESS,
87 MEMCACHED_SERVER_TEMPORARILY_DISABLED,
88 MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */
89 };
90
91 #ifndef __cplusplus
92 typedef enum memcached_return_t memcached_return_t;
93 #endif
94
95 static inline bool memcached_success(memcached_return_t rc)
96 {
97 return (rc == MEMCACHED_BUFFERED ||
98 rc == MEMCACHED_DELETED ||
99 rc == MEMCACHED_END ||
100 rc == MEMCACHED_ITEM ||
101 rc == MEMCACHED_STAT ||
102 rc == MEMCACHED_STORED ||
103 rc == MEMCACHED_SUCCESS ||
104 rc == MEMCACHED_VALUE);
105 }
106
107 static inline bool memcached_failed(memcached_return_t rc)
108 {
109 return (rc != MEMCACHED_SUCCESS &&
110 rc != MEMCACHED_END &&
111 rc != MEMCACHED_STORED &&
112 rc != MEMCACHED_STAT &&
113 rc != MEMCACHED_DELETED &&
114 rc != MEMCACHED_BUFFERED &&
115 rc != MEMCACHED_VALUE);
116 }
117
118 static inline bool memcached_fatal(memcached_return_t rc)
119 {
120 return (rc != MEMCACHED_SUCCESS &&
121 rc != MEMCACHED_END &&
122 rc != MEMCACHED_STORED &&
123 rc != MEMCACHED_STAT &&
124 rc != MEMCACHED_DELETED &&
125 rc != MEMCACHED_BUFFERED &&
126 rc != MEMCACHED_VALUE);
127 }
128
129 #define memcached_continue(__memcached_return_t) ((__memcached_return_t) == MEMCACHED_IN_PROGRESS)