Back to index

php5  5.3.10
php_stream_mmap.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Wez Furlong <wez@thebrainroom.com>                           |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_stream_mmap.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 /* Memory Mapping interface for streams.
00022  * The intention is to provide a uniform interface over the most common
00023  * operations that are used within PHP itself, rather than a complete
00024  * API for all memory mapping needs.
00025  *
00026  * ATM, we support only mmap(), but win32 memory mapping support will
00027  * follow soon.
00028  * */
00029 
00030 typedef enum {
00031        /* Does the stream support mmap ? */
00032        PHP_STREAM_MMAP_SUPPORTED,
00033        /* Request a range and offset to be mapped;
00034         * while mapped, you MUST NOT use any read/write functions
00035         * on the stream (win9x compatibility) */
00036        PHP_STREAM_MMAP_MAP_RANGE,
00037        /* Unmap the last range that was mapped for the stream */
00038        PHP_STREAM_MMAP_UNMAP
00039 } php_stream_mmap_operation_t;
00040        
00041 typedef enum {
00042        PHP_STREAM_MAP_MODE_READONLY,
00043        PHP_STREAM_MAP_MODE_READWRITE,
00044        PHP_STREAM_MAP_MODE_SHARED_READONLY,
00045        PHP_STREAM_MAP_MODE_SHARED_READWRITE
00046 } php_stream_mmap_access_t;
00047 
00048 typedef struct {
00049        /* requested offset and length.
00050         * If length is 0, the whole file is mapped */
00051        size_t offset;
00052        size_t length;
00053        
00054        php_stream_mmap_access_t mode;
00055        
00056        /* returned mapped address */
00057        char *mapped;
00058 
00059 } php_stream_mmap_range;
00060 
00061 #define PHP_STREAM_MMAP_ALL 0
00062 
00063 #define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL TSRMLS_CC) == 0 ? 1 : 0)
00064 
00065 /* Returns 1 if the stream in its current state can be memory mapped,
00066  * 0 otherwise */
00067 #define php_stream_mmap_possible(stream)                (!php_stream_is_filtered((stream)) && php_stream_mmap_supported((stream)))
00068 
00069 BEGIN_EXTERN_C()
00070 PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t length, php_stream_mmap_operation_t mode, size_t *mapped_len TSRMLS_DC);
00071 #define php_stream_mmap_range(stream, offset, length, mode, mapped_len)      _php_stream_mmap_range((stream), (offset), (length), (mode), (mapped_len) TSRMLS_CC)
00072 
00073 /* un-maps the last mapped range */
00074 PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC);
00075 #define php_stream_mmap_unmap(stream)                          _php_stream_mmap_unmap((stream) TSRMLS_CC)
00076 
00077 PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC);
00078 #define php_stream_mmap_unmap_ex(stream, readden)                     _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC)
00079 END_EXTERN_C()
00080 
00081 /*
00082  * Local variables:
00083  * tab-width: 4
00084  * c-basic-offset: 4
00085  * End:
00086  * vim600: noet sw=4 ts=4 fdm=marker
00087  * vim<600: noet sw=4 ts=4
00088  */