2 // This file is part of the aMule Project.
4 // Copyright (c) 2009 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2009 Frediano Ziglio (freddy77@gamilc.com)
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "CFile.h" // Needed for CFile
28 * This class is used to optimize file read/write using mapped memory
35 * Creates a uninitialized file area.
41 * Destructor, closes the file if opened.
51 * Init area with a given piece of file.
53 * @param file file to read.
54 * @param count bytes to read.
56 * Initialize buffer. Buffer will contain data from current file
57 * position for count length. Buffer will be a memory mapped area
58 * or a allocated buffer depending on systems.
60 * At the end file is positioned past readed area.
62 void Read(const CFile
& file
, size_t count
);
65 * Flushes data not yet written.
70 * Get buffer that contains data readed or to write.
71 * @return allocated buffer or NULL if not initialized
73 byte
*GetBuffer() const { return m_buffer
; };
76 //! A CFileArea is neither copyable nor assignable.
78 CFileArea(const CFileArea
&);
79 CFileArea
& operator=(const CFileArea
&);
83 * Pointer to buffer used for read/write operations.
84 * If mapped points inside m_mmap_buffer area otherwise
85 * point to an allocated buffer to be freed.
89 * Pointer to memory mapped area or NULL if not mapped.
93 * Length of the mapped region, currently used only for munmap.
97 * File descriptor or 'fd_invalid' if not opened.
98 * This file descriptor is used to write file if not mapped.
104 // File_checked_for_headers