* 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);
* @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
* @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;
* @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);
/**
* 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
*/
/**
* 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*/
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 */
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)
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;
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;
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;
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,
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 */
/* 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 */
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;
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) {
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;
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;
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;
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,
&slotmem_attach,
&slotmem_mem,
&slotmem_lock,
- &slotmem_unlock
+ &slotmem_unlock,
+ &slotmem_get,
+ &slotmem_put
};
/* make the storage usuable from outside */
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));
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));
}
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,