/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
/* XXX Unfortunately, there are still many unsigned ints in use here, so we *XXXcannotallowmorethanUINT_MAX.Sincesomeoftheintsareexposedin *XXXpublicinterfaces,asimplesearchandreplaceisnotenough. *XXXItshouldbepossibletoextendthatsothatthetotalcachesizecan *XXXbeAPR_SIZE_MAXandonlytheobjectsizeneedstobesmallerthan *XXXUINT_MAX.
*/ #define SHMCB_MAX_SIZE (UINT_MAX<APR_SIZE_MAX ? UINT_MAX : APR_SIZE_MAX)
/* *Headerstructure-thestartoftheshared-memsegment
*/ typedefstruct { /* Stats for cache operations */ unsignedlong stat_stores; unsignedlong stat_replaced; unsignedlong stat_expiries; unsignedlong stat_scrolled; unsignedlong stat_retrieves_hit; unsignedlong stat_retrieves_miss; unsignedlong stat_removes_hit; unsignedlong stat_removes_miss; /* Number of subcaches */ unsignedint subcache_num; /* How many indexes each subcache's queue has */ unsignedint index_num; /* How large each subcache is, including the queue and data */ unsignedint subcache_size; /* How far into each subcache the data area is (optimisation) */ unsignedint subcache_data_offset; /* How large the data area in each subcache is (optimisation) */ unsignedint subcache_data_size;
} SHMCBHeader;
/* *Subcachestructure-thestartofeachsubcache,followedby *indexesthendata
*/ typedefstruct { /* The start position and length of the cyclic buffer of indexes */ unsignedint idx_pos, idx_used; /* Same for the data area */ unsignedint data_pos, data_used;
} SHMCBSubcache;
/* *Indexstructure-eachsubcachehasanarrayofthese
*/ typedefstruct { /* absolute time this entry expires */
apr_time_t expires; /* location within the subcache's data area */ unsignedint data_pos; /* size (most logic ignores this, we keep it only to minimise memcpy) */ unsignedint data_used; /* length of the used data which contains the id */ unsignedint id_len; /* Used to mark explicitly-removed socache entries */ unsignedchar removed;
} SHMCBIndex;
/* The SHM data segment is of fixed size and stores data as follows. * *[SHMCBHeader|Subcaches] * *TheSHMCBHeaderheaderstructurestoresmetadataconcerningthe *cacheandthecontainedsubcaches. * *Subcachesisahashtableofheader->subcache_numSHMCBSubcache *structures.ThehashtableisindexedbySHMCB_MASK(id).Each *SHMCBSubcachestructurehasafixedsize(header->subcache_size), *whichisdeterminedatcreationtime,andlookslikethefollowing: * *[SHMCBSubcache|Indexes|Data] * *EachsubcacheisprefixedbytheSHMCBSubcachestructure. * *Thesubcache's"Data"segmentisasinglecyclicdatabuffer,of *totalsizeheader->subcache_data_size;datainsideisreferenced *usingbyteoffsets.Theoffsetmarkingthebeginningofthecyclic *bufferissubcache->data_pos;thebuffer'slengthis *subcache->data_used. * *"Indexes"isanarrayofheader->index_numSHMCBIndexstructures, *whichisusedasacyclicqueue;subcache->idx_posgivesthearray *indexofthefirstinuse,subcache->idx_usedgivesthenumberin *use.Both->idx_*valueshavearangeof[0,header->index_num) * *Eachin-useSHMCBIndexstructurerepresentsasinglecachedobject. *TheIDanddatasegmentarestoredconsecutivelyinthesubcache's *cyclicdatabuffer.The"Data"segmentcanthusbeseento *looklikethis,forexample * *offset:[0123456... *contents:[ID1Data1ID2Data2ID3... * *wherethecorrespondingindiceswouldlooklike: * *idx1={data_pos=0,data_used=3,id_len=1,...} *idx2={data_pos=3,data_used=3,id_len=1,...} *...
*/
/* This macro takes a pointer to the header and a zero-based index and returns
* a pointer to the corresponding subcache. */ #define SHMCB_SUBCACHE(pHeader, num) \
(SHMCBSubcache *)(((unsignedchar *)(pHeader)) + \
ALIGNED_HEADER_SIZE + \
(num) * ((pHeader)->subcache_size))
/* This macro takes a pointer to the header and an id and returns a
* pointer to the corresponding subcache. */ #define SHMCB_MASK(pHeader, id) \
SHMCB_SUBCACHE((pHeader), *(id) & ((pHeader)->subcache_num - 1))
/* This macro takes the same params as the last, generating two outputs for use
* in ap_log_error(...). */ #define SHMCB_MASK_DBG(pHeader, id) \
*(id), (*(id) & ((pHeader)->subcache_num - 1))
/* This macro takes a pointer to a subcache and a zero-based index and returns
* a pointer to the corresponding SHMCBIndex. */ #define SHMCB_INDEX(pSubcache, num) \
(SHMCBIndex *)(((unsignedchar *)pSubcache) + \
ALIGNED_SUBCACHE_SIZE + \
(num) * ALIGNED_INDEX_SIZE)
/* This macro takes a pointer to the header and a subcache and returns a
* pointer to the corresponding data area. */ #define SHMCB_DATA(pHeader, pSubcache) \
((unsignedchar *)(pSubcache) + (pHeader)->subcache_data_offset)
/* A "normal-to-cyclic" memcpy. */ staticvoid shmcb_cyclic_ntoc_memcpy(unsignedint buf_size, unsignedchar *data, unsignedint dest_offset, constunsignedchar *src, unsignedint src_len)
{ if (dest_offset + src_len < buf_size) /* It be copied all in one go */
memcpy(data + dest_offset, src, src_len); else { /* Copy the two splits */
memcpy(data + dest_offset, src, buf_size - dest_offset);
memcpy(data, src + buf_size - dest_offset,
src_len + dest_offset - buf_size);
}
}
/* A "cyclic-to-normal" memcpy. */ staticvoid shmcb_cyclic_cton_memcpy(unsignedint buf_size, unsignedchar *dest, constunsignedchar *data, unsignedint src_offset, unsignedint src_len)
{ if (src_offset + src_len < buf_size) /* It be copied all in one go */
memcpy(dest, data + src_offset, src_len); else { /* Copy the two splits */
memcpy(dest, data + src_offset, buf_size - src_offset);
memcpy(dest + buf_size - src_offset, data,
src_len + src_offset - buf_size);
}
}
/* A memcmp against a cyclic data buffer. Compares SRC of length *SRC_LENagainstthecontentsofcyclicbufferDATA(whichisof
* size BUF_SIZE), starting at offset DEST_OFFSET. Got that? Good. */ staticint shmcb_cyclic_memcmp(unsignedint buf_size, unsignedchar *data, unsignedint dest_offset, constunsignedchar *src, unsignedint src_len)
{ if (dest_offset + src_len < buf_size) /* It be compared all in one go */ return memcmp(data + dest_offset, src, src_len); else { /* Compare the two splits */ int diff;
/* Use anonymous shm by default, fall back on name-based. */
rv = apr_shm_create(&ctx->shm, ctx->shm_size, NULL, p); if (APR_STATUS_IS_ENOTIMPL(rv)) { /* If anon shm isn't supported, fail if no named file was *configuredsuccessfully;theap_server_root_relativecall
* above will return NULL for invalid paths. */ if (ctx->data_file == NULL) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00818) "Could not use anonymous shm for '%s' cache", namespace);
ctx->shm = NULL; return APR_EINVAL;
}
/* For a name-based segment, remove it first in case of a
* previous unclean shutdown. */
apr_shm_remove(ctx->data_file, p);
/* Sanity check the input */ if (total_len > header->subcache_data_size) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00844) "inserting socache entry larger (%d) than subcache data area (%d)",
total_len, header->subcache_data_size); return -1;
}
/* First reclaim space from removed and expired records. */
shmcb_subcache_expire(s, header, subcache, apr_time_now());
/* Loop until there is enough space to insert *XXX:Thisshouldfirstcompressout-of-orderexpiriesand *removedrecords,andthenforce-removeoldest-first
*/ if (header->subcache_data_size - subcache->data_used < total_len
|| subcache->idx_used == header->index_num) {
/* Only consider 'idx' if the id matches, and the "removed"
* flag isn't set. */ if (!idx->removed && idx->id_len == idlen
&& shmcb_cyclic_memcmp(header->subcache_data_size,
SHMCB_DATA(header, subcache),
idx->data_pos, id, idx->id_len) == 0) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00852) "possible match at idx=%d, data=%d", pos, idx->data_pos);
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.18Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.