From: Jim Jagielski Date: Tue, 10 Feb 2009 15:16:24 +0000 (+0000) Subject: Add getter/setter functions to the slotmem API. Also, X-Git-Tag: 2.3.2~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=615577723030c34737182a49c49f6ab07b98f760;p=thirdparty%2Fapache%2Fhttpd.git Add getter/setter functions to the slotmem API. Also, reset the id vars to unsigned ints universally. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@742992 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/ap_slotmem.h b/include/ap_slotmem.h index 2e966595579..48efacf6262 100644 --- a/include/ap_slotmem.h +++ b/include/ap_slotmem.h @@ -56,7 +56,7 @@ typedef struct ap_slotmem_t ap_slotmem_t; * callback function used for slotmem. * @param mem is the memory associated with a worker. * @param data is what is passed to slotmem. - * @param pool is pool used to create scoreboard + * @param pool is pool used * @return APR_SUCCESS if all went well */ typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool); @@ -71,40 +71,38 @@ struct ap_slotmem_storage_method { * @param s ap_slotmem_t to use. * @param funct callback function to call for each element. * @param data parameter for the callback function. - * @param pool is pool used to create scoreboard + * @param pool is pool used * @return APR_SUCCESS if all went well */ apr_status_t (* slotmem_do)(ap_slotmem_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool); /** * create a new slotmem with each item size is item_size. * This would create shared memory, basically. - * @param pointer to store the address of the scoreboard. * @param name is a key used for debugging and in mod_status output or allow another process to share this space. * @param item_size size of each item * @param item_num number of item to create. - * @param pool is pool used to create scoreboard + * @param pool is pool used * @return APR_SUCCESS if all went well */ - apr_status_t (* slotmem_create)(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool); + apr_status_t (* slotmem_create)(ap_slotmem_t **new, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool); /** * attach to an existing slotmem. * This would attach to shared memory, basically. - * @param pointer to store the address of the scoreboard. * @param name is a key used for debugging and in mod_status output or allow another process to share this space. * @param item_size size of each item * @param item_num max number of item. * @param pool is pool to memory allocate. * @return APR_SUCCESS if all went well */ - apr_status_t (* slotmem_attach)(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool); + apr_status_t (* slotmem_attach)(ap_slotmem_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool); /** - * get the memory associated with this worker slot. + * get the memory ptr associated with this worker slot. * @param s ap_slotmem_t to use. * @param item_id item to return for 0 to item_num * @param mem address to store the pointer to the slot * @return APR_SUCCESS if all went well */ - apr_status_t (* slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem); + apr_status_t (* slotmem_mem)(ap_slotmem_t *s, unsigned int item_id, void**mem); /** * lock the memory segment * NOTE: All slots share the same mutex @@ -119,6 +117,24 @@ struct ap_slotmem_storage_method { * @return APR_SUCCESS if all went well */ apr_status_t (* slotmem_unlock)(ap_slotmem_t *s); + /** + * retrieve the memory associated with this worker slot. + * @param s ap_slotmem_t to use. + * @param item_id item to return for 0 to item_num + * @param dest address to store the data + * @param dest_len length of dataset to retrieve + * @return APR_SUCCESS if all went well + */ + apr_status_t (* slotmem_get)(ap_slotmem_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len); + /** + * store the memory associated with this worker slot. + * @param s ap_slotmem_t to use. + * @param item_id item to return for 0 to item_num + * @param src address of the data to store in the slot + * @param src_len length of dataset to store in the slot + * @return APR_SUCCESS if all went well + */ + apr_status_t (* slotmem_put)(ap_slotmem_t *slot, unsigned int item_id, unsigned char *src, apr_size_t src_len); }; typedef struct ap_slotmem_storage_method ap_slotmem_storage_method; @@ -149,7 +165,7 @@ AP_DECLARE(ap_slotmem_storage_method *) ap_slotmem_method(const char *provider); * @param s ap_slotmem_t to use. * @param funct callback function to call for each element. * @param data parameter for the callback function. - * @param pool is pool used to create scoreboard + * @param pool is pool used * @return APR_SUCCESS if all went well */ AP_DECLARE(apr_status_t) ap_slotmem_do(ap_slotmem_storage_method *sm, ap_slotmem_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool); @@ -157,37 +173,39 @@ AP_DECLARE(apr_status_t) ap_slotmem_do(ap_slotmem_storage_method *sm, ap_slotmem /** * create a new slotmem with each item size is item_size. * This would create shared memory, basically. - * @param pointer to store the address of the scoreboard. + * @param sm ap_slotmem_storage_method provider obtained * @param name is a key used for debugging and in mod_status output or allow another process to share this space. * @param item_size size of each item * @param item_num number of item to create. - * @param pool is pool used to create scoreboard + * @param pool is pool used * @return APR_SUCCESS if all went well */ -AP_DECLARE(apr_status_t) ap_slotmem_create(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool); +AP_DECLARE(apr_status_t) ap_slotmem_create(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool); /** * attach to an existing slotmem. * This would attach to shared memory, basically. - * @param pointer to store the address of the scoreboard. + * @param sm ap_slotmem_storage_method provider obtained * @param name is a key used for debugging and in mod_status output or allow another process to share this space. * @param item_size size of each item * @param item_num max number of item. * @param pool is pool to memory allocate. * @return APR_SUCCESS if all went well */ -AP_DECLARE(apr_status_t) ap_slotmem_attach(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool); +AP_DECLARE(apr_status_t) ap_slotmem_attach(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool); /** * get the memory associated with this worker slot. + * @param sm ap_slotmem_storage_method provider obtained * @param s ap_slotmem_t to use. * @param item_id item to return for 0 to item_num * @param mem address to store the pointer to the slot * @return APR_SUCCESS if all went well */ -AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm, ap_slotmem_t *s, int item_id, void**mem); +AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned int item_id, void**mem); /** * lock the memory segment * NOTE: All slots share the same mutex + * @param sm ap_slotmem_storage_method provider obtained * @param s ap_slotmem_t to use * @return APR_SUCCESS if all went well */ @@ -195,9 +213,30 @@ AP_DECLARE(apr_status_t) ap_slotmem_lock(ap_slotmem_storage_method *sm, ap_slotm /** * unlock the memory segment * NOTE: All slots share the same mutex + * @param sm ap_slotmem_storage_method provider obtained * @param s ap_slotmem_t to use. * @return APR_SUCCESS if all went well */ AP_DECLARE(apr_status_t) ap_slotmem_unlock(ap_slotmem_storage_method *sm, ap_slotmem_t *s); +/** + * retrieve the memory associated with this worker slot. + * @param sm ap_slotmem_storage_method provider obtained + * @param s ap_slotmem_t to use. + * @param item_id item to return for 0 to item_num + * @param dest address to store the data + * @param dest_len length of dataset to retrieve + * @return APR_SUCCESS if all went well + */ +AP_DECLARE(apr_status_t) ap_slotmem_get(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len); +/** + * store the memory associated with this worker slot. + * @param sm ap_slotmem_storage_method provider obtained + * @param s ap_slotmem_t to use. + * @param item_id item to return for 0 to item_num + * @param src address of the data to store in the slot + * @param src_len length of dataset to store in the slot + * @return APR_SUCCESS if all went well + */ +AP_DECLARE(apr_status_t) ap_slotmem_put(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned int item_id, unsigned char *src, apr_size_t src_len); #endif /*SLOTMEM_H*/ diff --git a/modules/mem/mod_plainmem.c b/modules/mem/mod_plainmem.c index 90ba950f87d..ca6a2fee335 100644 --- a/modules/mem/mod_plainmem.c +++ b/modules/mem/mod_plainmem.c @@ -24,7 +24,7 @@ struct ap_slotmem_t { char *name; /* per segment name */ void *base; /* data set start */ apr_size_t size; /* size of each memory slot */ - int num; /* number of mem slots */ + unsigned int num; /* number of mem slots */ apr_pool_t *gpool; /* per segment global pool */ apr_global_mutex_t *smutex; /* mutex */ struct ap_slotmem_t *next; /* location of next allocated segment */ @@ -37,7 +37,7 @@ static apr_pool_t *gpool = NULL; static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool) { - int i; + unsigned int i; void *ptr; if (!mem) @@ -51,7 +51,7 @@ static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func return APR_SUCCESS; } -static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool) +static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool) { ap_slotmem_t *res; ap_slotmem_t *next = globallistmem; @@ -100,7 +100,7 @@ static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_siz return APR_SUCCESS; } -static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool) +static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool) { ap_slotmem_t *next = globallistmem; const char *fname; @@ -133,7 +133,7 @@ static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_siz return APR_ENOSHMAVAIL; } -static apr_status_t slotmem_mem(ap_slotmem_t *score, int id, void **mem) +static apr_status_t slotmem_mem(ap_slotmem_t *score, unsigned int id, void **mem) { void *ptr; @@ -150,6 +150,34 @@ static apr_status_t slotmem_mem(ap_slotmem_t *score, int id, void **mem) return APR_SUCCESS; } +static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned char *dest, apr_size_t dest_len) +{ + + void *ptr; + apr_status_t ret; + + ret = slotmem_mem(slot, id, &ptr); + if (ret != APR_SUCCESS) { + return ret; + } + memcpy(dest, ptr, dest_len); /* bounds check? */ + return APR_SUCCESS; +} + +static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned char *src, apr_size_t src_len) +{ + + void *ptr; + apr_status_t ret; + + ret = slotmem_mem(slot, id, &ptr); + if (ret != APR_SUCCESS) { + return ret; + } + memcpy(ptr, src, src_len); /* bounds check? */ + return APR_SUCCESS; +} + static const ap_slotmem_storage_method storage = { "plainmem", &slotmem_do, diff --git a/modules/mem/mod_sharedmem.c b/modules/mem/mod_sharedmem.c index 868391d8c15..becc4fa2585 100644 --- a/modules/mem/mod_sharedmem.c +++ b/modules/mem/mod_sharedmem.c @@ -25,7 +25,7 @@ struct ap_slotmem_t { void *shm; /* ptr to memory segment (apr_shm_t *) */ void *base; /* data set start */ apr_size_t size; /* size of each memory slot */ - int num; /* number of mem slots */ + unsigned int num; /* number of mem slots */ apr_pool_t *gpool; /* per segment global pool */ apr_global_mutex_t *smutex; /* mutex */ struct ap_slotmem_t *next; /* location of next allocated segment */ @@ -35,7 +35,7 @@ struct ap_slotmem_t { /* The description of the slots to reuse the slotmem */ struct sharedslotdesc { apr_size_t item_size; - int item_num; + unsigned int item_num; }; /* global pool and list of slotmem we are handling */ @@ -92,7 +92,7 @@ static void store_slotmem(ap_slotmem_t *slotmem) apr_file_close(fp); } -static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool) +static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool) { const char *storename; apr_file_t *fp; @@ -138,7 +138,7 @@ static apr_status_t cleanup_slotmem(void *param) static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool) { - int i; + unsigned int i; void *ptr; if (!mem) { @@ -153,7 +153,7 @@ static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func return APR_SUCCESS; } -static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool) +static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool) { /* void *slotmem = NULL; */ void *ptr; @@ -255,7 +255,7 @@ static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_siz return APR_SUCCESS; } -static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool) +static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool) { /* void *slotmem = NULL; */ void *ptr; @@ -331,7 +331,7 @@ static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_siz return APR_SUCCESS; } -static apr_status_t slotmem_mem(ap_slotmem_t *slot, int id, void **mem) +static apr_status_t slotmem_mem(ap_slotmem_t *slot, unsigned int id, void **mem) { void *ptr; @@ -361,6 +361,34 @@ static apr_status_t slotmem_unlock(ap_slotmem_t *slot) return (apr_global_mutex_unlock(slot->smutex)); } +static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned char *dest, apr_size_t dest_len) +{ + + void *ptr; + apr_status_t ret; + + ret = slotmem_mem(slot, id, &ptr); + if (ret != APR_SUCCESS) { + return ret; + } + memcpy(dest, ptr, dest_len); /* bounds check? */ + return APR_SUCCESS; +} + +static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned char *src, apr_size_t src_len) +{ + + void *ptr; + apr_status_t ret; + + ret = slotmem_mem(slot, id, &ptr); + if (ret != APR_SUCCESS) { + return ret; + } + memcpy(ptr, src, src_len); /* bounds check? */ + return APR_SUCCESS; +} + static const ap_slotmem_storage_method storage = { "sharedmem", &slotmem_do, @@ -368,7 +396,9 @@ static const ap_slotmem_storage_method storage = { &slotmem_attach, &slotmem_mem, &slotmem_lock, - &slotmem_unlock + &slotmem_unlock, + &slotmem_get, + &slotmem_put }; /* make the storage usuable from outside */ diff --git a/server/slotmem.c b/server/slotmem.c index 9af25a7699d..d31583b33da 100644 --- a/server/slotmem.c +++ b/server/slotmem.c @@ -41,7 +41,7 @@ AP_DECLARE(apr_status_t) ap_slotmem_do(ap_slotmem_storage_method *sm, AP_DECLARE(apr_status_t) ap_slotmem_create(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, - apr_size_t item_size, int item_num, + apr_size_t item_size, unsigned int item_num, apr_pool_t *pool) { return (sm->slotmem_create(new, name, item_size, item_num, pool)); @@ -49,14 +49,14 @@ AP_DECLARE(apr_status_t) ap_slotmem_create(ap_slotmem_storage_method *sm, AP_DECLARE(apr_status_t) ap_slotmem_attach(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, - apr_size_t *item_size, int *item_num, + apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool) { return (sm->slotmem_attach(new, name, item_size, item_num, pool)); } AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm, - ap_slotmem_t *s, int item_id, void**mem) + ap_slotmem_t *s, unsigned int item_id, void**mem) { return (sm->slotmem_mem(s, item_id, mem)); } @@ -73,6 +73,18 @@ AP_DECLARE(apr_status_t) ap_slotmem_unlock(ap_slotmem_storage_method *sm, return (sm->slotmem_unlock(s)); } +AP_DECLARE(apr_status_t) ap_slotmem_get(ap_slotmem_storage_method *sm, + ap_slotmem_t *s, unsigned int item_id, + unsigned char *dest, apr_size_t dest_len) +{ + return (sm->slotmem_get(s, item_id, dest, dest_len)); +} +AP_DECLARE(apr_status_t) ap_slotmem_put(ap_slotmem_storage_method *sm, ap_slotmem_t *s, + unsigned int item_id, unsigned char *src, + apr_size_t src_len) +{ + return (sm->slotmem_put(s, item_id, src, src_len)); +} module AP_MODULE_DECLARE_DATA slotmem_module = { STANDARD20_MODULE_STUFF,