28#define APR_WANT_STRFUNC
45#define SHMCB_MAX_SIZE (UINT_MAX<APR_SIZE_MAX ? UINT_MAX : APR_SIZE_MAX)
47#define DEFAULT_SHMCB_PREFIX "socache-shmcb-"
49#define DEFAULT_SHMCB_SUFFIX ".cache"
51#define ALIGNED_HEADER_SIZE APR_ALIGN_DEFAULT(sizeof(SHMCBHeader))
52#define ALIGNED_SUBCACHE_SIZE APR_ALIGN_DEFAULT(sizeof(SHMCBSubcache))
53#define ALIGNED_INDEX_SIZE APR_ALIGN_DEFAULT(sizeof(SHMCBIndex))
159#define SHMCB_SUBCACHE(pHeader, num) \
160 (SHMCBSubcache *)(((unsigned char *)(pHeader)) + \
161 ALIGNED_HEADER_SIZE + \
162 (num) * ((pHeader)->subcache_size))
166#define SHMCB_MASK(pHeader, id) \
167 SHMCB_SUBCACHE((pHeader), *(id) & ((pHeader)->subcache_num - 1))
171#define SHMCB_MASK_DBG(pHeader, id) \
172 *(id), (*(id) & ((pHeader)->subcache_num - 1))
176#define SHMCB_INDEX(pSubcache, num) \
177 (SHMCBIndex *)(((unsigned char *)pSubcache) + \
178 ALIGNED_SUBCACHE_SIZE + \
179 (num) * ALIGNED_INDEX_SIZE)
183#define SHMCB_DATA(pHeader, pSubcache) \
184 ((unsigned char *)(pSubcache) + (pHeader)->subcache_data_offset)
191#define SHMCB_CYCLIC_INCREMENT(val,inc,mod) \
192 (((val) + (inc)) % (mod))
195#define SHMCB_CYCLIC_SPACE(val1,val2,mod) \
196 ((val2) >= (val1) ? ((val2) - (val1)) : \
197 ((val2) + (mod) - (val1)))
236 const unsigned char *
src,
263 const unsigned char *
id,
unsigned int id_len,
267 const unsigned char *
id,
unsigned int idlen,
268 unsigned char *
data,
unsigned int *datalen);
271 const unsigned char *,
unsigned int);
301 ctx->shm_size = 1024*512;
303 if (!
arg || *
arg ==
'\0') {
315 return "Invalid argument: no closing parenthesis or cache size "
316 "missing after pathname with parenthesis";
324 return "Invalid argument: cache size not numerical";
327 if (
ctx->shm_size < 8192) {
328 return "Invalid argument: size has to be >= 8192 bytes";
339 return "Invalid argument: no opening parenthesis";
356 const char *
namespace,
383 "Could not use anonymous shm for '%s' cache",
398 "Could not allocate shared memory segment for shmcb "
411 "shared memory segment too small");
416 " bytes of shared memory",
421 avg_obj_size =
hints &&
hints->avg_obj_size ?
hints->avg_obj_size : 150;
430 " including header), recommending %u subcaches, "
437 "shared memory segment too small");
466 "shmcb_init_memory choices follow");
484 "Shared memory socache initialised");
500 unsigned char *encoded,
509 "socache_shmcb_store (0x%02x -> subcache %d)",
514 "(%u bytes)",
idlen);
521 "can't store an socache entry!");
531 "leaving socache_shmcb_store successfully");
537 const unsigned char *
id,
unsigned int idlen,
546 "socache_shmcb_retrieve (0x%02x -> subcache %d)",
557 "leaving socache_shmcb_retrieve successfully");
571 "socache_shmcb_remove (0x%02x -> subcache %d)",
575 "(%u bytes)",
idlen);
586 "leaving socache_shmcb_remove successfully");
632 "bytes, current entries: <b>%d</b><br>",
633 ctx->shm_size, total);
634 ap_rprintf(
r,
"subcaches: <b>%d</b>, indexes per subcache: <b>%d</b><br>",
638 ap_rprintf(
r,
"time left on oldest entries' objects: ");
640 ap_rprintf(
r,
"avg: <b>%d</b> seconds, (range: %d...%d)<br>",
645 ap_rprintf(
r,
"expiry_threshold: <b>Calculation error!</b><br>");
648 ap_rprintf(
r,
"index usage: <b>%d%%</b>, cache usage: <b>%d%%</b><br>",
650 ap_rprintf(
r,
"total entries stored since starting: <b>%lu</b><br>",
652 ap_rprintf(
r,
"total entries replaced since starting: <b>%lu</b><br>",
654 ap_rprintf(
r,
"total entries expired since starting: <b>%lu</b><br>",
656 ap_rprintf(
r,
"total (pre-expiry) entries scrolled out of the cache: "
658 ap_rprintf(
r,
"total retrieves since starting: <b>%lu</b> hit, "
661 ap_rprintf(
r,
"total removes since starting: <b>%lu</b> hit, "
734 else if (
idx->expires <=
now)
746 "expiring %u and reclaiming %u removed socache entries",
766 "we now have %u socache entries",
subcache->idx_used);
772 const unsigned char *
id,
unsigned int id_len,
782 "inserting socache entry larger (%d) than subcache data area (%d)",
799 "about to force-expire, subcache: idx_used=%d, "
825 "finished force-expire, subcache: idx_used=%d, "
854 idx->expires = expiry;
857 idx->id_len = id_len;
861 "insert happened at idx=%d, data=(%u:%u)",
new_idx,
864 "finished insert, subcache: idx_pos/idx_used=%d/%d, "
865 "data_pos/data_used=%d/%d",
873 const unsigned char *
id,
unsigned int idlen,
877 unsigned int loop = 0;
895 idx->data_pos,
id,
idx->id_len) == 0) {
897 "match at idx=%d, data=%d", pos,
idx->data_pos);
920 "shmcb_subcache_retrieve discarding expired entry");
930 "shmcb_subcache_retrieve found no match");
936 const unsigned char *
id,
940 unsigned int loop = 0;
951 idx->data_pos,
id,
idx->id_len) == 0) {
953 "possible match at idx=%d, data=%d", pos,
idx->data_pos);
958 "shmcb_subcache_remove removing matching entry");
982 unsigned int loop = 0;
993 "iterating idx=%d, data=%d", pos,
idx->data_pos);
995 unsigned char *
id = *
buf;
1024 idx->data_pos,
idx->id_len);
1025 id[
idx->id_len] =
'\0';
1035 "shmcb entry iterated");
1044 "shmcb_subcache_iterate discarding expired entry");
Small object cache provider interface.
APR Miscellaneous library routines.
APR Shared Memory Routines.
APR Standard Headers Support.
char * ap_runtime_dir_relative(apr_pool_t *p, const char *fname)
#define AP_DECLARE_MODULE(foo)
char * ap_server_root_relative(apr_pool_t *p, const char *fname)
request_rec int int apr_table_t const char * path
const unsigned char * buf
int ap_rprintf(request_rec *r, const char *fmt,...) __attribute__((format(printf
static APR_INLINE int ap_rputs(const char *str, request_rec *r)
apr_status_t ap_register_provider(apr_pool_t *pool, const char *provider_group, const char *provider_name, const char *provider_version, const void *provider)
#define APR_STATUS_IS_ENOTIMPL(s)
apr_brigade_flush void * ctx
const char apr_ssize_t int flags
const char const apr_size_t data_len
#define AP_SOCACHE_DEFAULT_PROVIDER
apr_status_t() ap_socache_iterator_t(ap_socache_instance_t *instance, server_rec *s, void *userctx, const unsigned char *id, unsigned int idlen, const unsigned char *data, unsigned int datalen, apr_pool_t *pool)
#define AP_SOCACHE_PROVIDER_GROUP
#define AP_SOCACHE_FLAG_NOTMPSAFE
#define AP_SOCACHE_PROVIDER_VERSION
#define STANDARD20_MODULE_STUFF
#define AP_DEBUG_ASSERT(exp)
const char int apr_pool_t * pool
#define APR_ALIGN_DEFAULT(size)
#define apr_pcalloc(p, size)
#define apr_time_sec(time)
static apr_status_t socache_shmcb_store(ap_socache_instance_t *ctx, server_rec *s, const unsigned char *id, unsigned int idlen, apr_time_t expiry, unsigned char *encoded, unsigned int len_encoded, apr_pool_t *p)
static void socache_shmcb_destroy(ap_socache_instance_t *ctx, server_rec *s)
#define ALIGNED_HEADER_SIZE
#define SHMCB_MASK_DBG(pHeader, id)
static const char * socache_shmcb_create(ap_socache_instance_t **context, const char *arg, apr_pool_t *tmp, apr_pool_t *p)
static apr_status_t socache_shmcb_iterate(ap_socache_instance_t *instance, server_rec *s, void *userctx, ap_socache_iterator_t *iterator, apr_pool_t *pool)
static int shmcb_subcache_retrieve(server_rec *, SHMCBHeader *, SHMCBSubcache *, const unsigned char *id, unsigned int idlen, unsigned char *data, unsigned int *datalen)
#define DEFAULT_SHMCB_SUFFIX
#define SHMCB_INDEX(pSubcache, num)
static const ap_socache_provider_t socache_shmcb
static void shmcb_cyclic_ntoc_memcpy(unsigned int buf_size, unsigned char *data, unsigned int dest_offset, const unsigned char *src, unsigned int src_len)
#define SHMCB_CYCLIC_INCREMENT(val, inc, mod)
#define SHMCB_SUBCACHE(pHeader, num)
static apr_status_t socache_shmcb_init(ap_socache_instance_t *ctx, const char *namespace, const struct ap_socache_hints *hints, server_rec *s, apr_pool_t *p)
static void register_hooks(apr_pool_t *p)
static int shmcb_subcache_remove(server_rec *, SHMCBHeader *, SHMCBSubcache *, const unsigned char *, unsigned int)
static apr_status_t socache_shmcb_remove(ap_socache_instance_t *ctx, server_rec *s, const unsigned char *id, unsigned int idlen, apr_pool_t *p)
static void socache_shmcb_status(ap_socache_instance_t *ctx, request_rec *r, int flags)
static apr_status_t socache_shmcb_cleanup(void *arg)
static int shmcb_cyclic_memcmp(unsigned int buf_size, unsigned char *data, unsigned int dest_offset, const unsigned char *src, unsigned int src_len)
#define SHMCB_CYCLIC_SPACE(val1, val2, mod)
static int shmcb_subcache_store(server_rec *s, SHMCBHeader *header, SHMCBSubcache *subcache, unsigned char *data, unsigned int data_len, const unsigned char *id, unsigned int id_len, apr_time_t expiry)
#define ALIGNED_SUBCACHE_SIZE
static void shmcb_subcache_expire(server_rec *, SHMCBHeader *, SHMCBSubcache *, apr_time_t)
#define SHMCB_MASK(pHeader, id)
#define ALIGNED_INDEX_SIZE
#define SHMCB_DATA(pHeader, pSubcache)
static apr_status_t socache_shmcb_retrieve(ap_socache_instance_t *ctx, server_rec *s, const unsigned char *id, unsigned int idlen, unsigned char *dest, unsigned int *destlen, apr_pool_t *p)
static apr_status_t shmcb_subcache_iterate(ap_socache_instance_t *instance, server_rec *s, void *userctx, SHMCBHeader *header, SHMCBSubcache *subcache, ap_socache_iterator_t *iterator, unsigned char **buf, apr_size_t *buf_len, apr_pool_t *pool, apr_time_t now)
#define DEFAULT_SHMCB_PREFIX
static void shmcb_cyclic_cton_memcpy(unsigned int buf_size, unsigned char *dest, const unsigned char *data, unsigned int src_offset, unsigned int src_len)
Status Report Extension Module to Apache.
A structure that represents the current request.
A structure to store information for each virtual server.