home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / Apache / apache_2.0.52-win32-x86-no_ssl.msi / Data.Cab / F277216_apr_mmap.h < prev    next >
C/C++ Source or Header  |  2004-02-13  |  6KB  |  193 lines

  1. /* Copyright 2000-2004 The Apache Software Foundation
  2.  *
  3.  * Licensed under the Apache License, Version 2.0 (the "License");
  4.  * you may not use this file except in compliance with the License.
  5.  * You may obtain a copy of the License at
  6.  *
  7.  *     http://www.apache.org/licenses/LICENSE-2.0
  8.  *
  9.  * Unless required by applicable law or agreed to in writing, software
  10.  * distributed under the License is distributed on an "AS IS" BASIS,
  11.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12.  * See the License for the specific language governing permissions and
  13.  * limitations under the License.
  14.  */
  15.  
  16. #ifndef APR_MMAP_H
  17. #define APR_MMAP_H
  18.  
  19. /**
  20.  * @file apr_mmap.h
  21.  * @brief APR MMAP routines
  22.  */
  23.  
  24. #include "apr.h"
  25. #include "apr_pools.h"
  26. #include "apr_errno.h"
  27. #include "apr_ring.h"
  28. #include "apr_file_io.h"        /* for apr_file_t */
  29.  
  30. #ifdef BEOS
  31. #include <kernel/OS.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif /* __cplusplus */
  37.  
  38. /**
  39.  * @defgroup apr_mmap MMAP (Memory Map) Routines
  40.  * @ingroup APR 
  41.  * @{
  42.  */
  43.  
  44. /** MMap opened for reading */
  45. #define APR_MMAP_READ    1
  46. /** MMap opened for writing */
  47. #define APR_MMAP_WRITE   2
  48.  
  49. /** @see apr_mmap_t */
  50. typedef struct apr_mmap_t            apr_mmap_t;
  51.  
  52. /**
  53.  * @remark
  54.  * As far as I can tell the only really sane way to store an MMAP is as a
  55.  * void * and a length.  BeOS requires this area_id, but that's just a little
  56.  * something extra.  I am exposing this type, because it doesn't make much
  57.  * sense to keep it private, and opening it up makes some stuff easier in
  58.  * Apache.
  59.  */
  60. /** The MMAP structure */
  61. struct apr_mmap_t {
  62.     /** The pool the mmap structure was allocated out of. */
  63.     apr_pool_t *cntxt;
  64. #ifdef BEOS
  65.     /** An area ID.  Only valid on BeOS */
  66.     area_id area;
  67. #endif
  68. #ifdef WIN32
  69.     /** The handle of the file mapping */
  70.     HANDLE mhandle;
  71.     /** The start of the real memory page area (mapped view) */
  72.     void *mv;
  73.     /** The physical start, size and offset */
  74.     apr_off_t  pstart;
  75.     apr_size_t psize;
  76.     apr_off_t  poffset;
  77. #endif
  78.     /** The start of the memory mapped area */
  79.     void *mm;
  80.     /** The amount of data in the mmap */
  81.     apr_size_t size;
  82.     /** @deprecated this field is no longer used and will be removed
  83.      * in APR 1.0 */
  84.     int unused;
  85.     /** ring of apr_mmap_t's that reference the same
  86.      * mmap'ed region; acts in place of a reference count */
  87.     APR_RING_ENTRY(apr_mmap_t) link;
  88. };
  89.  
  90. #if APR_HAS_MMAP || defined(DOXYGEN)
  91.  
  92. /** @def APR_MMAP_THRESHOLD 
  93.  * Files have to be at least this big before they're mmap()d.  This is to deal
  94.  * with systems where the expense of doing an mmap() and an munmap() outweighs
  95.  * the benefit for small files.  It shouldn't be set lower than 1.
  96.  */
  97. #ifdef MMAP_THRESHOLD
  98. #  define APR_MMAP_THRESHOLD              MMAP_THRESHOLD
  99. #else
  100. #  ifdef SUNOS4
  101. #    define APR_MMAP_THRESHOLD            (8*1024)
  102. #  else
  103. #    define APR_MMAP_THRESHOLD            1
  104. #  endif /* SUNOS4 */
  105. #endif /* MMAP_THRESHOLD */
  106.  
  107. /** @def APR_MMAP_LIMIT
  108.  * Maximum size of MMap region
  109.  */
  110. #ifdef MMAP_LIMIT
  111. #  define APR_MMAP_LIMIT                  MMAP_LIMIT
  112. #else
  113. #  define APR_MMAP_LIMIT                  (4*1024*1024)
  114. #endif /* MMAP_LIMIT */
  115.  
  116. /** Can this file be MMaped */
  117. #define APR_MMAP_CANDIDATE(filelength) \
  118.     ((filelength >= APR_MMAP_THRESHOLD) && (filelength < APR_MMAP_LIMIT))
  119.  
  120. /*   Function definitions */
  121.  
  122. /** 
  123.  * Create a new mmap'ed file out of an existing APR file.
  124.  * @param newmmap The newly created mmap'ed file.
  125.  * @param file The file turn into an mmap.
  126.  * @param offset The offset into the file to start the data pointer at.
  127.  * @param size The size of the file
  128.  * @param flag bit-wise or of:
  129.  * <PRE>
  130.  *          APR_MMAP_READ       MMap opened for reading
  131.  *          APR_MMAP_WRITE      MMap opened for writing
  132.  * </PRE>
  133.  * @param cntxt The pool to use when creating the mmap.
  134.  */
  135. APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap, 
  136.                                           apr_file_t *file, apr_off_t offset,
  137.                                           apr_size_t size, apr_int32_t flag,
  138.                                           apr_pool_t *cntxt);
  139.  
  140. /**
  141.  * Duplicate the specified MMAP.
  142.  * @param new_mmap The structure to duplicate into. 
  143.  * @param old_mmap The mmap to duplicate.
  144.  * @param p The pool to use for new_mmap.
  145.  * @param transfer_ownership DEPRECATED: this param is now ignored
  146.  *  and should be removed prior to APR 1.0
  147.  */         
  148. APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
  149.                                        apr_mmap_t *old_mmap,
  150.                                        apr_pool_t *p,
  151.                                        int transfer_ownership);
  152.  
  153. #if defined(DOXYGEN)
  154. /**
  155.  * Transfer the specified MMAP to a different pool
  156.  * @param new_mmap The structure to duplicate into.
  157.  * @param old_mmap The file to transfer.
  158.  * @param p The pool to use for new_mmap.
  159.  * @deprecated Just use apr_mmap_dup().  The transfer_ownership flag will
  160.  *  go away soon anyway.
  161.  */
  162. APR_DECLARE(apr_status_t) apr_mmap_setaside(apr_mmap_t **new_mmap,
  163.                                             apr_mmap_t *old_mmap,
  164.                                             apr_pool_t *p);
  165. #else
  166. #define apr_mmap_setaside(new_mmap, old_mmap, p) apr_mmap_dup(new_mmap, old_mmap, p, 1)
  167. #endif /* DOXYGEN */
  168.  
  169. /**
  170.  * Remove a mmap'ed.
  171.  * @param mm The mmap'ed file.
  172.  */
  173. APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm);
  174.  
  175. /** 
  176.  * Move the pointer into the mmap'ed file to the specified offset.
  177.  * @param addr The pointer to the offset specified.
  178.  * @param mm The mmap'ed file.
  179.  * @param offset The offset to move to.
  180.  */
  181. APR_DECLARE(apr_status_t) apr_mmap_offset(void **addr, apr_mmap_t *mm, 
  182.                                           apr_off_t offset);
  183.  
  184. #endif /* APR_HAS_MMAP */
  185.  
  186. /** @} */
  187.  
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191.  
  192. #endif  /* ! APR_MMAP_H */
  193.