]> granicus.if.org Git - apache/blob - include/ap_slotmem.h
igalic reminded me that AllowOverride now defaults to none, and Options
[apache] / include / ap_slotmem.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef SLOTMEM_H
18 #define SLOTMEM_H
19
20 /* Memory handler for a shared memory divided in slot.
21  */
22 /**
23  * @file  ap_slotmem.h
24  * @brief Memory Slot Extension Storage Module for Apache
25  *
26  * @defgroup MEM mem
27  * @ingroup  APACHE_MODS
28  * @{
29  */
30
31 #include "httpd.h"
32 #include "http_config.h"
33 #include "http_log.h"
34 #include "ap_provider.h"
35
36 #include "apr.h"
37 #include "apr_strings.h"
38 #include "apr_pools.h"
39 #include "apr_shm.h"
40 #include "apr_global_mutex.h"
41 #include "apr_file_io.h"
42
43 #if APR_HAVE_UNISTD_H
44 #include <unistd.h>         /* for getpid() */
45 #endif
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #define AP_SLOTMEM_PROVIDER_GROUP "slotmem"
52 #define AP_SLOTMEM_PROVIDER_VERSION 0
53
54 typedef unsigned int ap_slotmem_type_t;
55
56 /*
57  * Values for ap_slotmem_type_t::
58  *
59  * AP_SLOTMEM_TYPE_PERSIST: For transitory providers, persist
60  *    the data on the file-system
61  *
62  * AP_SLOTMEM_TYPE_NOTMPSAFE:
63  *
64  * AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st
65  */
66 #define AP_SLOTMEM_TYPE_PERSIST   (1 << 0)
67 #define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1)
68 #define AP_SLOTMEM_TYPE_PREGRAB   (1 << 2)
69
70 typedef struct ap_slotmem_instance_t ap_slotmem_instance_t;
71
72 /**
73  * callback function used for slotmem.
74  * @param mem is the memory associated with a worker.
75  * @param data is what is passed to slotmem.
76  * @param pool is pool used
77  * @return APR_SUCCESS if all went well
78  */
79 typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool);
80
81 struct ap_slotmem_provider_t {
82     /*
83      * Name of the provider method
84      */
85     const char *name;
86     /**
87      * call the callback on all worker slots
88      * @param s ap_slotmem_instance_t to use.
89      * @param funct callback function to call for each element.
90      * @param data parameter for the callback function.
91      * @param pool is pool used
92      * @return APR_SUCCESS if all went well
93      */
94     apr_status_t (* doall)(ap_slotmem_instance_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
95     /**
96      * create a new slotmem with each item size is item_size.
97      * This would create shared memory, basically.
98      * @param name is a key used for debugging and in mod_status output or allow another process to share this space.
99      * @param item_size size of each item
100      * @param item_num number of item to create.
101      * @param type type of slotmem.
102      * @param pool is pool used
103      * @return APR_SUCCESS if all went well
104      */
105     apr_status_t (* create)(ap_slotmem_instance_t **new, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool);
106     /**
107      * attach to an existing slotmem.
108      * This would attach to  shared memory, basically.
109      * @param name is a key used for debugging and in mod_status output or allow another process to share this space.
110      * @param item_size size of each item
111      * @param item_num max number of item.
112      * @param pool is pool to memory allocate.
113      * @return APR_SUCCESS if all went well
114      */
115     apr_status_t (* attach)(ap_slotmem_instance_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool);
116     /**
117      * get the memory ptr associated with this worker slot.
118      * @param s ap_slotmem_instance_t to use.
119      * @param item_id item to return for 0 to item_num
120      * @param mem address to store the pointer to the slot
121      * @return APR_SUCCESS if all went well
122      */
123     apr_status_t (* dptr)(ap_slotmem_instance_t *s, unsigned int item_id, void**mem);
124     /**
125      * get/read the data associated with this worker slot.
126      * @param s ap_slotmem_instance_t to use.
127      * @param item_id item to return for 0 to item_num
128      * @param dest address to store the data
129      * @param dest_len length of dataset to retrieve
130      * @return APR_SUCCESS if all went well
131      */
132     apr_status_t (* get)(ap_slotmem_instance_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len);
133     /**
134      * put/write the data associated with this worker slot.
135      * @param s ap_slotmem_instance_t to use.
136      * @param item_id item to return for 0 to item_num
137      * @param src address of the data to store in the slot
138      * @param src_len length of dataset to store in the slot
139      * @return APR_SUCCESS if all went well
140      */
141     apr_status_t (* put)(ap_slotmem_instance_t *slot, unsigned int item_id, unsigned char *src, apr_size_t src_len);
142     /**
143      * return number of slots allocated for this entry.
144      * @param s ap_slotmem_instance_t to use.
145      * @return number of slots
146      */
147     unsigned int (* num_slots)(ap_slotmem_instance_t *s);
148     /**
149      * return number of free (not used) slots allocated for this entry.
150      * Valid for slots which are AP_SLOTMEM_TYPE_PREGRAB as well as
151      * any which use get/release. 
152      * @param s ap_slotmem_instance_t to use.
153      * @return number of slots
154      */
155     unsigned int (* num_free_slots)(ap_slotmem_instance_t *s);
156     /**
157      * return slot size allocated for this entry.
158      * @param s ap_slotmem_instance_t to use.
159      * @return size of slot
160      */
161     apr_size_t (* slot_size)(ap_slotmem_instance_t *s);
162     /**
163      * grab (or alloc) a free slot
164      * @param s ap_slotmem_instance_t to use.
165      * @param item_id ptr to the available slot id and marked as in-use
166      * @return APR_SUCCESS if all went well
167      */
168     apr_status_t (* grab)(ap_slotmem_instance_t *s, unsigned int *item_id);
169     /**
170      * release (or free) the slot associated with this item_id
171      * @param s ap_slotmem_instance_t to use.
172      * @param item_id slot id to free and mark as no longer in-use
173      * @return APR_SUCCESS if all went well
174      */
175     apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id);
176 };
177
178 typedef struct ap_slotmem_provider_t ap_slotmem_provider_t;
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif
185 /** @} */