1 /* 2 Copyright (C) 2007-2008 Tomash Brechko. All rights reserved. 3 4 When used to build Perl module: 5 6 This library is free software; you can redistribute it and/or modify 7 it under the same terms as Perl itself, either Perl version 5.8.8 8 or, at your option, any later version of Perl 5 you may have 9 available. 10 11 When used as a standalone library: 12 13 This library is free software; you can redistribute it and/or modify 14 it under the terms of the GNU Lesser General Public License as 15 published by the Free Software Foundation; either version 2.1 of the 16 License, or (at your option) any later version. 17 18 This library is distributed in the hope that it will be useful, but 19 WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 Lesser General Public License for more details. 22 */ 23 24 #ifndef CLIENT_H 25 #define CLIENT_H 1 26 27 #include <stddef.h> 28 29 30 struct client; 31 32 33 enum server_status { 34 MEMCACHED_SUCCESS, 35 MEMCACHED_FAILURE, 36 MEMCACHED_EAGAIN, 37 MEMCACHED_ERROR, 38 MEMCACHED_UNKNOWN, 39 MEMCACHED_CLOSED 40 }; 41 42 enum set_cmd_e { CMD_SET, CMD_ADD, CMD_REPLACE, CMD_APPEND, CMD_PREPEND, 43 CMD_CAS }; 44 45 enum get_cmd_e { CMD_GET, CMD_GETS }; 46 47 enum gat_cmd_e { CMD_GAT, CMD_GATS }; 48 49 enum arith_cmd_e { CMD_INCR, CMD_DECR }; 50 51 52 typedef unsigned int flags_type; 53 #define FMT_FLAGS "%u" 54 55 typedef int exptime_type; 56 #define FMT_EXPTIME "%d" 57 58 typedef unsigned int delay_type; 59 #define FMT_DELAY "%u" 60 61 typedef unsigned long value_size_type; 62 #define FMT_VALUE_SIZE "%lu" 63 64 typedef unsigned long long cas_type; 65 #define FMT_CAS "%llu" 66 67 typedef unsigned long long arith_type; 68 #define FMT_ARITH "%llu" 69 70 71 typedef void *(*alloc_value_func)(value_size_type value_size, void **opaque); 72 typedef void (*store_value_func)(void *arg, void *opaque, int key_index, 73 void *meta); 74 typedef void (*free_value_func)(void *opaque); 75 76 struct result_object 77 { 78 alloc_value_func alloc; 79 store_value_func store; 80 free_value_func free; 81 82 void *arg; 83 }; 84 85 struct meta_object 86 { 87 flags_type flags; 88 int use_cas; 89 cas_type cas; 90 }; 91 92 93 extern 94 struct client * 95 client_init(); 96 97 extern 98 void 99 client_destroy(struct client *c); 100 101 extern 102 void 103 client_reinit(struct client *c); 104 105 /* 106 client_set_ketama_points() should be called before adding any server. 107 */ 108 extern 109 int 110 client_set_ketama_points(struct client *c, int ketama_points); 111 112 /* 113 client_set_hash_namespace() should be called before setting the 114 namespace. 115 */ 116 extern 117 void 118 client_set_hash_namespace(struct client *c, int enable); 119 120 extern 121 int 122 client_add_server(struct client *c, const char *host, size_t host_len, 123 const char *port, size_t port_len, double weight, 124 int noreply); 125 126 extern 127 int 128 client_set_prefix(struct client *c, const char *ns, size_t ns_len); 129 130 extern 131 const char * 132 client_get_prefix(struct client *c, size_t *ns_len); 133 134 extern 135 void 136 client_set_connect_timeout(struct client *c, int to); 137 138 extern 139 void 140 client_set_io_timeout(struct client *c, int to); 141 142 extern 143 void 144 client_set_max_failures(struct client *c, int f); 145 146 extern 147 void 148 client_set_failure_timeout(struct client *c, int to); 149 150 extern 151 void 152 client_set_close_on_error(struct client *c, int enable); 153 154 extern 155 void 156 client_set_nowait(struct client *c, int enable); 157 158 extern 159 void 160 client_reset(struct client *c, struct result_object *o, int noreply); 161 162 extern 163 int 164 client_prepare_set(struct client *c, enum set_cmd_e cmd, int key_index, 165 const char *key, size_t key_len, 166 flags_type flags, exptime_type exptime, 167 const void *value, value_size_type value_size); 168 169 extern 170 int 171 client_prepare_cas(struct client *c, int key_index, 172 const char *key, size_t key_len, 173 cas_type cas, flags_type flags, exptime_type exptime, 174 const void *value, value_size_type value_size); 175 176 extern 177 int 178 client_prepare_get(struct client *c, enum get_cmd_e cmd, int key_index, 179 const char *key, size_t key_len); 180 181 extern 182 int 183 client_prepare_gat(struct client *c, enum gat_cmd_e cmd, 184 int key_index, const char *key, size_t key_len, const char *exptime, size_t exptime_len); 185 186 extern 187 int 188 client_prepare_incr(struct client *c, enum arith_cmd_e cmd, int key_index, 189 const char *key, size_t key_len, arith_type arg); 190 191 extern 192 int 193 client_prepare_delete(struct client *c, int key_index, 194 const char *key, size_t key_len); 195 196 extern 197 int 198 client_prepare_touch(struct client *c, int key_index, 199 const char* key, size_t key_len, 200 exptime_type exptime); 201 202 extern 203 int 204 client_execute(struct client *c, int key_index); 205 206 extern 207 int 208 client_flush_all(struct client *c, delay_type delay, 209 struct result_object *o, int noreply); 210 211 extern 212 int 213 client_nowait_push(struct client *c); 214 215 extern 216 int 217 client_server_versions(struct client *c, struct result_object *o); 218 219 220 #endif /* ! CLIENT_H */ 221