Apache Portable Runtime Utility Library
|
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_MEMCACHE_H 00018 #define APR_MEMCACHE_H 00019 00028 #include "apr.h" 00029 #include "apr_pools.h" 00030 #include "apr_time.h" 00031 #include "apr_strings.h" 00032 #include "apr_network_io.h" 00033 #include "apr_ring.h" 00034 #include "apr_buckets.h" 00035 #include "apr_reslist.h" 00036 #include "apr_hash.h" 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif /* __cplusplus */ 00041 00049 typedef enum 00050 { 00051 APR_MC_SERVER_LIVE, 00052 APR_MC_SERVER_DEAD 00053 } apr_memcache_server_status_t; 00054 00056 typedef struct apr_memcache_conn_t apr_memcache_conn_t; 00057 00059 typedef struct apr_memcache_server_t apr_memcache_server_t; 00060 struct apr_memcache_server_t 00061 { 00062 const char *host; 00063 apr_port_t port; 00064 apr_memcache_server_status_t status; 00065 #if APR_HAS_THREADS || defined(DOXYGEN) 00066 apr_reslist_t *conns; 00067 #else 00068 apr_memcache_conn_t *conn; 00069 #endif 00070 apr_pool_t *p; 00071 #if APR_HAS_THREADS 00072 apr_thread_mutex_t *lock; 00073 #endif 00074 apr_time_t btime; 00075 }; 00076 00077 /* Custom hash callback function prototype, user for server selection. 00078 * @param baton user selected baton 00079 * @param data data to hash 00080 * @param data_len length of data 00081 */ 00082 typedef apr_uint32_t (*apr_memcache_hash_func)(void *baton, 00083 const char *data, 00084 const apr_size_t data_len); 00085 00086 typedef struct apr_memcache_t apr_memcache_t; 00087 00088 /* Custom Server Select callback function prototype. 00089 * @param baton user selected baton 00090 * @param mc memcache instance, use mc->live_servers to select a node 00091 * @param hash hash of the selected key. 00092 */ 00093 typedef apr_memcache_server_t* (*apr_memcache_server_func)(void *baton, 00094 apr_memcache_t *mc, 00095 const apr_uint32_t hash); 00096 00098 struct apr_memcache_t 00099 { 00100 apr_uint32_t flags; 00101 apr_uint16_t nalloc; 00102 apr_uint16_t ntotal; 00103 apr_memcache_server_t **live_servers; 00104 apr_pool_t *p; 00105 void *hash_baton; 00106 apr_memcache_hash_func hash_func; 00107 void *server_baton; 00108 apr_memcache_server_func server_func; 00109 }; 00110 00112 typedef struct 00113 { 00114 apr_status_t status; 00115 const char* key; 00116 apr_size_t len; 00117 char *data; 00118 apr_uint16_t flags; 00119 } apr_memcache_value_t; 00120 00129 APU_DECLARE(apr_uint32_t) apr_memcache_hash(apr_memcache_t *mc, 00130 const char *data, 00131 const apr_size_t data_len); 00132 00136 APU_DECLARE(apr_uint32_t) apr_memcache_hash_crc32(void *baton, 00137 const char *data, 00138 const apr_size_t data_len); 00139 00143 APU_DECLARE(apr_uint32_t) apr_memcache_hash_default(void *baton, 00144 const char *data, 00145 const apr_size_t data_len); 00146 00154 APU_DECLARE(apr_memcache_server_t *) apr_memcache_find_server_hash(apr_memcache_t *mc, 00155 const apr_uint32_t hash); 00156 00160 APU_DECLARE(apr_memcache_server_t *) apr_memcache_find_server_hash_default(void *baton, 00161 apr_memcache_t *mc, 00162 const apr_uint32_t hash); 00163 00172 APU_DECLARE(apr_status_t) apr_memcache_add_server(apr_memcache_t *mc, 00173 apr_memcache_server_t *server); 00174 00175 00183 APU_DECLARE(apr_memcache_server_t *) apr_memcache_find_server(apr_memcache_t *mc, 00184 const char *host, 00185 apr_port_t port); 00186 00192 APU_DECLARE(apr_status_t) apr_memcache_enable_server(apr_memcache_t *mc, 00193 apr_memcache_server_t *ms); 00194 00195 00201 APU_DECLARE(apr_status_t) apr_memcache_disable_server(apr_memcache_t *mc, 00202 apr_memcache_server_t *ms); 00203 00217 APU_DECLARE(apr_status_t) apr_memcache_server_create(apr_pool_t *p, 00218 const char *host, 00219 apr_port_t port, 00220 apr_uint32_t min, 00221 apr_uint32_t smax, 00222 apr_uint32_t max, 00223 apr_uint32_t ttl, 00224 apr_memcache_server_t **ns); 00232 APU_DECLARE(apr_status_t) apr_memcache_create(apr_pool_t *p, 00233 apr_uint16_t max_servers, 00234 apr_uint32_t flags, 00235 apr_memcache_t **mc); 00236 00247 APU_DECLARE(apr_status_t) apr_memcache_getp(apr_memcache_t *mc, 00248 apr_pool_t *p, 00249 const char* key, 00250 char **baton, 00251 apr_size_t *len, 00252 apr_uint16_t *flags); 00253 00254 00263 APU_DECLARE(void) apr_memcache_add_multget_key(apr_pool_t *data_pool, 00264 const char* key, 00265 apr_hash_t **values); 00266 00277 APU_DECLARE(apr_status_t) apr_memcache_multgetp(apr_memcache_t *mc, 00278 apr_pool_t *temp_pool, 00279 apr_pool_t *data_pool, 00280 apr_hash_t *values); 00281 00291 APU_DECLARE(apr_status_t) apr_memcache_set(apr_memcache_t *mc, 00292 const char *key, 00293 char *baton, 00294 const apr_size_t data_size, 00295 apr_uint32_t timeout, 00296 apr_uint16_t flags); 00297 00309 APU_DECLARE(apr_status_t) apr_memcache_add(apr_memcache_t *mc, 00310 const char *key, 00311 char *baton, 00312 const apr_size_t data_size, 00313 apr_uint32_t timeout, 00314 apr_uint16_t flags); 00315 00327 APU_DECLARE(apr_status_t) apr_memcache_replace(apr_memcache_t *mc, 00328 const char *key, 00329 char *baton, 00330 const apr_size_t data_size, 00331 apr_uint32_t timeout, 00332 apr_uint16_t flags); 00339 APU_DECLARE(apr_status_t) apr_memcache_delete(apr_memcache_t *mc, 00340 const char *key, 00341 apr_uint32_t timeout); 00342 00350 APU_DECLARE(apr_status_t) apr_memcache_incr(apr_memcache_t *mc, 00351 const char *key, 00352 apr_int32_t n, 00353 apr_uint32_t *nv); 00354 00362 APU_DECLARE(apr_status_t) apr_memcache_decr(apr_memcache_t *mc, 00363 const char *key, 00364 apr_int32_t n, 00365 apr_uint32_t *new_value); 00366 00374 APU_DECLARE(apr_status_t) apr_memcache_version(apr_memcache_server_t *ms, 00375 apr_pool_t *p, 00376 char **baton); 00377 00378 typedef struct 00379 { 00381 const char *version; 00383 apr_uint32_t pid; 00385 apr_uint32_t uptime; 00387 apr_time_t time; 00389 apr_uint32_t pointer_size; 00391 apr_time_t rusage_user; 00393 apr_time_t rusage_system; 00395 apr_uint32_t curr_items; 00397 apr_uint32_t total_items; 00399 apr_uint64_t bytes; 00401 apr_uint32_t curr_connections; 00403 apr_uint32_t total_connections; 00405 apr_uint32_t connection_structures; 00407 apr_uint32_t cmd_get; 00409 apr_uint32_t cmd_set; 00411 apr_uint32_t get_hits; 00413 apr_uint32_t get_misses; 00416 apr_uint64_t evictions; 00418 apr_uint64_t bytes_read; 00420 apr_uint64_t bytes_written; 00422 apr_uint32_t limit_maxbytes; 00424 apr_uint32_t threads; 00425 } apr_memcache_stats_t; 00426 00433 APU_DECLARE(apr_status_t) apr_memcache_stats(apr_memcache_server_t *ms, 00434 apr_pool_t *p, 00435 apr_memcache_stats_t **stats); 00436 00437 00440 #ifdef __cplusplus 00441 } 00442 #endif 00443 00444 #endif /* APR_MEMCACHE_H */