| 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 arith_cmd_e { CMD_INCR, CMD_DECR }; |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | typedef unsigned int flags_type; |
|---|
| 51 | #define FMT_FLAGS "%u" |
|---|
| 52 | |
|---|
| 53 | typedef int exptime_type; |
|---|
| 54 | #define FMT_EXPTIME "%d" |
|---|
| 55 | |
|---|
| 56 | typedef unsigned int delay_type; |
|---|
| 57 | #define FMT_DELAY "%u" |
|---|
| 58 | |
|---|
| 59 | typedef unsigned long value_size_type; |
|---|
| 60 | #define FMT_VALUE_SIZE "%lu" |
|---|
| 61 | |
|---|
| 62 | typedef unsigned long long cas_type; |
|---|
| 63 | #define FMT_CAS "%llu" |
|---|
| 64 | |
|---|
| 65 | typedef unsigned long long arith_type; |
|---|
| 66 | #define FMT_ARITH "%llu" |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | typedef void *(*alloc_value_func)(value_size_type value_size, void **opaque); |
|---|
| 70 | typedef void (*store_value_func)(void *arg, void *opaque, int key_index, |
|---|
| 71 | void *meta); |
|---|
| 72 | typedef void (*free_value_func)(void *opaque); |
|---|
| 73 | |
|---|
| 74 | struct result_object |
|---|
| 75 | { |
|---|
| 76 | alloc_value_func alloc; |
|---|
| 77 | store_value_func store; |
|---|
| 78 | free_value_func free; |
|---|
| 79 | |
|---|
| 80 | void *arg; |
|---|
| 81 | }; |
|---|
| 82 | |
|---|
| 83 | struct meta_object |
|---|
| 84 | { |
|---|
| 85 | flags_type flags; |
|---|
| 86 | int use_cas; |
|---|
| 87 | cas_type cas; |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | extern |
|---|
| 92 | struct client * |
|---|
| 93 | client_init(); |
|---|
| 94 | |
|---|
| 95 | extern |
|---|
| 96 | void |
|---|
| 97 | client_destroy(struct client *c); |
|---|
| 98 | |
|---|
| 99 | extern |
|---|
| 100 | void |
|---|
| 101 | client_reinit(struct client *c); |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | client_set_ketama_points() should be called before adding any server. |
|---|
| 105 | */ |
|---|
| 106 | extern |
|---|
| 107 | int |
|---|
| 108 | client_set_ketama_points(struct client *c, int ketama_points); |
|---|
| 109 | |
|---|
| 110 | /* |
|---|
| 111 | client_set_hash_namespace() should be called before setting the |
|---|
| 112 | namespace. |
|---|
| 113 | */ |
|---|
| 114 | extern |
|---|
| 115 | void |
|---|
| 116 | client_set_hash_namespace(struct client *c, int enable); |
|---|
| 117 | |
|---|
| 118 | extern |
|---|
| 119 | int |
|---|
| 120 | client_add_server(struct client *c, const char *host, size_t host_len, |
|---|
| 121 | const char *port, size_t port_len, double weight, |
|---|
| 122 | int noreply); |
|---|
| 123 | |
|---|
| 124 | extern |
|---|
| 125 | int |
|---|
| 126 | client_set_prefix(struct client *c, const char *ns, size_t ns_len); |
|---|
| 127 | |
|---|
| 128 | extern |
|---|
| 129 | const char * |
|---|
| 130 | client_get_prefix(struct client *c, size_t *ns_len); |
|---|
| 131 | |
|---|
| 132 | extern |
|---|
| 133 | void |
|---|
| 134 | client_set_connect_timeout(struct client *c, int to); |
|---|
| 135 | |
|---|
| 136 | extern |
|---|
| 137 | void |
|---|
| 138 | client_set_io_timeout(struct client *c, int to); |
|---|
| 139 | |
|---|
| 140 | extern |
|---|
| 141 | void |
|---|
| 142 | client_set_max_failures(struct client *c, int f); |
|---|
| 143 | |
|---|
| 144 | extern |
|---|
| 145 | void |
|---|
| 146 | client_set_failure_timeout(struct client *c, int to); |
|---|
| 147 | |
|---|
| 148 | extern |
|---|
| 149 | void |
|---|
| 150 | client_set_close_on_error(struct client *c, int enable); |
|---|
| 151 | |
|---|
| 152 | extern |
|---|
| 153 | void |
|---|
| 154 | client_set_nowait(struct client *c, int enable); |
|---|
| 155 | |
|---|
| 156 | extern |
|---|
| 157 | void |
|---|
| 158 | client_reset(struct client *c, struct result_object *o, int noreply); |
|---|
| 159 | |
|---|
| 160 | extern |
|---|
| 161 | int |
|---|
| 162 | client_prepare_set(struct client *c, enum set_cmd_e cmd, int key_index, |
|---|
| 163 | const char *key, size_t key_len, |
|---|
| 164 | flags_type flags, exptime_type exptime, |
|---|
| 165 | const void *value, value_size_type value_size); |
|---|
| 166 | |
|---|
| 167 | extern |
|---|
| 168 | int |
|---|
| 169 | client_prepare_cas(struct client *c, int key_index, |
|---|
| 170 | const char *key, size_t key_len, |
|---|
| 171 | cas_type cas, flags_type flags, exptime_type exptime, |
|---|
| 172 | const void *value, value_size_type value_size); |
|---|
| 173 | |
|---|
| 174 | extern |
|---|
| 175 | int |
|---|
| 176 | client_prepare_get(struct client *c, enum get_cmd_e cmd, int key_index, |
|---|
| 177 | const char *key, size_t key_len); |
|---|
| 178 | |
|---|
| 179 | extern |
|---|
| 180 | int |
|---|
| 181 | client_prepare_incr(struct client *c, enum arith_cmd_e cmd, int key_index, |
|---|
| 182 | const char *key, size_t key_len, arith_type arg); |
|---|
| 183 | |
|---|
| 184 | extern |
|---|
| 185 | int |
|---|
| 186 | client_prepare_delete(struct client *c, int key_index, |
|---|
| 187 | const char *key, size_t key_len); |
|---|
| 188 | |
|---|
| 189 | extern |
|---|
| 190 | int |
|---|
| 191 | client_execute(struct client *c); |
|---|
| 192 | |
|---|
| 193 | extern |
|---|
| 194 | int |
|---|
| 195 | client_flush_all(struct client *c, delay_type delay, |
|---|
| 196 | struct result_object *o, int noreply); |
|---|
| 197 | |
|---|
| 198 | extern |
|---|
| 199 | int |
|---|
| 200 | client_nowait_push(struct client *c); |
|---|
| 201 | |
|---|
| 202 | extern |
|---|
| 203 | int |
|---|
| 204 | client_server_versions(struct client *c, struct result_object *o); |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | #endif /* ! CLIENT_H */ |
|---|