|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef SLOTMEM_H
|
|
Packit |
90a5c9 |
#define SLOTMEM_H
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Memory handler for a shared memory divided in slot.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* @file ap_slotmem.h
|
|
Packit |
90a5c9 |
* @brief Memory Slot Extension Storage Module for Apache
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @defgroup MEM mem
|
|
Packit |
90a5c9 |
* @ingroup APACHE_MODS
|
|
Packit |
90a5c9 |
* @{
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
#include "http_config.h"
|
|
Packit |
90a5c9 |
#include "http_log.h"
|
|
Packit |
90a5c9 |
#include "ap_provider.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_pools.h"
|
|
Packit |
90a5c9 |
#include "apr_shm.h"
|
|
Packit |
90a5c9 |
#include "apr_global_mutex.h"
|
|
Packit |
90a5c9 |
#include "apr_file_io.h"
|
|
Packit |
90a5c9 |
#include "apr_md5.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if APR_HAVE_UNISTD_H
|
|
Packit |
90a5c9 |
#include <unistd.h> /* for getpid() */
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef __cplusplus
|
|
Packit |
90a5c9 |
extern "C" {
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_PROVIDER_GROUP "slotmem"
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_PROVIDER_VERSION "0"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef unsigned int ap_slotmem_type_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Values for ap_slotmem_type_t::
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* AP_SLOTMEM_TYPE_PERSIST: For transitory providers, persist
|
|
Packit |
90a5c9 |
* the data on the file-system
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* AP_SLOTMEM_TYPE_NOTMPSAFE:
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* AP_SLOTMEM_TYPE_CLEARINUSE: If persisting, clear 'inuse' array before
|
|
Packit |
90a5c9 |
* storing
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_TYPE_PERSIST (1 << 0)
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1)
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_TYPE_PREGRAB (1 << 2)
|
|
Packit |
90a5c9 |
#define AP_SLOTMEM_TYPE_CLEARINUSE (1 << 3)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct ap_slotmem_instance_t ap_slotmem_instance_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* callback function used for slotmem doall.
|
|
Packit |
90a5c9 |
* @param mem is the memory associated with a worker.
|
|
Packit |
90a5c9 |
* @param data is what is passed to slotmem.
|
|
Packit |
90a5c9 |
* @param pool is pool used
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct ap_slotmem_provider_t {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Name of the provider method
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
const char *name;
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* call the callback on all worker slots
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param funct callback function to call for each element.
|
|
Packit |
90a5c9 |
* @param data parameter for the callback function.
|
|
Packit |
90a5c9 |
* @param pool is pool used
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* doall)(ap_slotmem_instance_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* create a new slotmem with each item size is item_size.
|
|
Packit |
90a5c9 |
* This would create shared memory, basically.
|
|
Packit |
90a5c9 |
* @param inst where to store pointer to slotmem
|
|
Packit |
90a5c9 |
* @param name a key used for debugging and in mod_status output or allow another process to share this space.
|
|
Packit |
90a5c9 |
* @param item_size size of each item
|
|
Packit |
90a5c9 |
* @param item_num number of item to create.
|
|
Packit |
90a5c9 |
* @param type type of slotmem.
|
|
Packit |
90a5c9 |
* @param pool is pool used
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* create)(ap_slotmem_instance_t **inst, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* attach to an existing slotmem.
|
|
Packit |
90a5c9 |
* This would attach to shared memory, basically.
|
|
Packit |
90a5c9 |
* @param inst where to store pointer to slotmem
|
|
Packit |
90a5c9 |
* @param name a key used for debugging and in mod_status output or allow another process to share this space.
|
|
Packit |
90a5c9 |
* @param item_size size of each item
|
|
Packit |
90a5c9 |
* @param item_num max number of item.
|
|
Packit |
90a5c9 |
* @param pool is pool to memory allocate.
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* attach)(ap_slotmem_instance_t **inst, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* get the memory ptr associated with this worker slot.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id item to return for 0 to item_num
|
|
Packit |
90a5c9 |
* @param mem address to store the pointer to the slot
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* dptr)(ap_slotmem_instance_t *s, unsigned int item_id, void**mem);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* get/read the data associated with this worker slot.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id item to return for 0 to item_num
|
|
Packit |
90a5c9 |
* @param dest address to store the data
|
|
Packit |
90a5c9 |
* @param dest_len length of dataset to retrieve
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* get)(ap_slotmem_instance_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* put/write the data associated with this worker slot.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id item to return for 0 to item_num
|
|
Packit |
90a5c9 |
* @param src address of the data to store in the slot
|
|
Packit |
90a5c9 |
* @param src_len length of dataset to store in the slot
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* put)(ap_slotmem_instance_t *slot, unsigned int item_id, unsigned char *src, apr_size_t src_len);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* return number of slots allocated for this entry.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @return number of slots
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
unsigned int (* num_slots)(ap_slotmem_instance_t *s);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* return number of free (not used) slots allocated for this entry.
|
|
Packit |
90a5c9 |
* Valid for slots which are AP_SLOTMEM_TYPE_PREGRAB as well as
|
|
Packit |
90a5c9 |
* any which use get/release.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @return number of slots
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
unsigned int (* num_free_slots)(ap_slotmem_instance_t *s);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* return slot size allocated for this entry.
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @return size of slot
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_size_t (* slot_size)(ap_slotmem_instance_t *s);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* grab (or alloc) a free slot
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id ptr to the available slot id and marked as in-use
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* grab)(ap_slotmem_instance_t *s, unsigned int *item_id);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* release (or free) the slot associated with this item_id
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id slot id to free and mark as no longer in-use
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* forced grab (or alloc) a slot associated with this item_id
|
|
Packit |
90a5c9 |
* @param s ap_slotmem_instance_t to use.
|
|
Packit |
90a5c9 |
* @param item_id to the specified slot id and marked as in-use
|
|
Packit |
90a5c9 |
* @return APR_SUCCESS if all went well
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t (* fgrab)(ap_slotmem_instance_t *s, unsigned int item_id);
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct ap_slotmem_provider_t ap_slotmem_provider_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef __cplusplus
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
/** @} */
|