Bayonne2 / Common C++ 2 Framework
|
Create and map a disk file into memory. More...
#include <file.h>
Public Member Functions | |
MappedFile (const char *fname, Access mode) | |
Open a file for mapping. More... | |
MappedFile (const char *fname, Access mode, size_t size) | |
Create if not exists, and map a file of specified size into memory. More... | |
MappedFile (const char *fname, pos_t offset, size_t size, Access mode) | |
Map a portion or all of a specified file in the specified shared memory access mode. More... | |
virtual | ~MappedFile () |
Release a mapped section of memory associated with a file. More... | |
void | sync (void) |
Synchronize the contents of the mapped portion of memory with the disk file and wait for completion. More... | |
void | sync (char *address, size_t len) |
Synchronize a segment of memory mapped from a segment fetch. More... | |
void | update (size_t offset=0, size_t len=0) |
Map a portion of the memory mapped from the file back to the file and do not wait for completion. More... | |
void | update (char *address, size_t len) |
Update a mapped region back to disk as specified by address and length. More... | |
void | release (char *address, size_t len) |
Release (unmap) a memory segment. More... | |
char * | fetch (size_t offset=0) |
Fetch a pointer to an offset within the memory mapped portion of the disk file. More... | |
char * | fetch (off_t pos, size_t len) |
Fetch and map a portion of a disk file to a logical memory block. More... | |
bool | lock (void) |
Lock the currently mapped portion of a file. More... | |
void | unlock (void) |
Unlock a locked mapped portion of a file. More... | |
size_t | pageAligned (size_t size) |
Compute map size to aligned page boundry. More... | |
bool | initial (void) |
This method should be called right after a RandomFile derived object has been created. More... | |
off_t | getCapacity (void) |
Get current file capacity. More... | |
virtual Error | restart (void) |
This method is commonly used to close and re-open an existing database. More... | |
Error | getErrorNumber (void) |
Return current error id. More... | |
char * | getErrorString (void) |
Return current error string. More... | |
bool | operator! (void) |
Static Public Member Functions | |
static const char * | getExtension (const char *path) |
static const char * | getFilename (const char *path) |
static char * | getFilename (const char *path, char *buffer, size_t size=64) |
static char * | getDirname (const char *path, char *buffer, size_t size=256) |
static char * | getRealpath (const char *path, char *buffer, size_t size=256) |
Protected Types | |
typedef struct File::_fcb | fcb_t |
Protected Member Functions | |
Error | error (Error errid, char *errstr=NULL) |
Post an error event. More... | |
Error | error (char *err) |
Post an extended string error message. More... | |
void | setError (bool enable) |
Used to enable or disable throwing of exceptions on errors. More... | |
Error | setCompletion (Complete mode) |
Used to set file completion modes. More... | |
void | setTemporary (bool enable) |
Used to set the temporary attribute for the file. More... | |
virtual Attr | initialize (void) |
This method is used to initialize a newly created file as indicated by the "initial" flag. More... | |
void | final (void) |
Close the file. More... | |
void | nameMutex (const char *name) |
Enable setting of mutex name for deadlock debug. More... | |
void | enterMutex (void) |
Entering a Mutex locks the mutex for the current thread. More... | |
void | enter (void) |
Future abi will use enter/leave/test members. More... | |
void | leave (void) |
Future abi will use enter/leave/test members. More... | |
bool | test (void) |
Future abi will use enter/leave/test members. More... | |
bool | tryEnterMutex (void) |
Tries to lock the mutex for the current thread. More... | |
void | leaveMutex (void) |
Leaving a mutex frees that mutex for use by another thread. More... | |
Static Protected Member Functions | |
static void | setDebug (bool mode) |
Enable or disable deadlock debugging. More... | |
Protected Attributes | |
int | fd |
Access | access |
char * | pathname |
struct { | |
unsigned count: 16 | |
bool thrown: 1 | |
bool initial: 1 | |
bool immediate: 1 | |
bool temp: 1 | |
} | flags |
Private Attributes | |
fcb_t | fcb |
int | prot |
Related Functions | |
(Note that these are not member functions.) | |
bool __EXPORT | isDir (const char *path) |
bool __EXPORT | isFile (const char *path) |
bool __EXPORT | isDevice (const char *path) |
bool __EXPORT | canAccess (const char *path) |
bool __EXPORT | canModify (const char *path) |
time_t __EXPORT | lastModified (const char *path) |
time_t __EXPORT | lastAccessed (const char *path) |
Create and map a disk file into memory.
This portable class works under both Posix via mmap and under the win32 API. A mapped file can be referenced directly by it's memory segment. One can map and unmap portions of a file on demand, and update changed memory pages mapped from files immediately through sync().
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
protectedinherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
MappedFile::MappedFile | ( | const char * | fname, |
Access | mode | ||
) |
Open a file for mapping.
More than one segment of a file may be mapped into seperate regions of memory.
fname | file name to access for mapping. |
mode | access mode to map file. |
MappedFile::MappedFile | ( | const char * | fname, |
Access | mode, | ||
size_t | size | ||
) |
Create if not exists, and map a file of specified size into memory.
fname | file name to access for mapping. |
mode | access mode to map file. |
size | of file to map. |
Map a portion or all of a specified file in the specified shared memory access mode.
Valid mapping modes include mappedRead, mappedWrite, and mappedReadWrite.
fname | pathname of file to map into memory. |
offset | from start of file to begin mapping in bytes. |
size | of mapped area in bytes. |
mode | to map file. |
|
virtual |
Release a mapped section of memory associated with a file.
The mapped area is updated back to disk.
|
inlineinherited |
|
inherited |
Entering a Mutex locks the mutex for the current thread.
This also can be done using the ENTER_CRITICAL macro or by using the ++ operator on a mutex.
Post an error event.
errid | error code. |
errstr | error message string. |
|
inlineprotectedinherited |
|
inline |
Fetch a pointer to an offset within the memory mapped portion of the disk file.
This really is used for convience of matching operations between Update and Fetch, as one could simply have accessed the base pointer where the file was mapped directly.
offset | from start of mapped memory. |
char* MappedFile::fetch | ( | off_t | pos, |
size_t | len | ||
) |
Fetch and map a portion of a disk file to a logical memory block.
pos | offset of file segment to map. |
len | size of memory segment to map. |
|
protectedinherited |
Close the file.
|
inherited |
Get current file capacity.
|
staticinherited |
|
inlineinherited |
|
inlineinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
inherited |
This method should be called right after a RandomFile derived object has been created.
This method will invoke initialize if the object is newly created, and set file access permissions appropriately.
|
protectedvirtualinherited |
This method is used to initialize a newly created file as indicated by the "initial" flag.
This method also returns the file access permissions that should be associated with the file. This method should never be called directly, but is instead used to impliment the "Initial" method. Typically one would use this to build an empty database shell when a previously empty database file is created.
|
inlineinherited |
|
inherited |
Leaving a mutex frees that mutex for use by another thread.
If the mutex has been entered (invoked) multiple times (recursivily) by the same thread, then it will need to be exited the same number of instances before it is free for re-use. This operation can also be done using the LEAVE_CRITICAL macro or by the – operator on a mutex.
bool MappedFile::lock | ( | void | ) |
Lock the currently mapped portion of a file.
|
inlineinherited |
|
inherited |
size_t MappedFile::pageAligned | ( | size_t | size | ) |
Compute map size to aligned page boundry.
size | request. |
void MappedFile::release | ( | char * | address, |
size_t | len | ||
) |
Release (unmap) a memory segment.
address | address of memory segment to release. |
len | length of memory segment to release. |
|
virtualinherited |
This method is commonly used to close and re-open an existing database.
This may be used when the database has been unlinked and an external process provides a new one to use.
Reimplemented in SharedFile, and ThreadFile.
Used to set file completion modes.
mode | completion mode. |
|
inlinestaticinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
void MappedFile::sync | ( | void | ) |
Synchronize the contents of the mapped portion of memory with the disk file and wait for completion.
This assures the memory mapped from the file is written back.
void MappedFile::sync | ( | char * | address, |
size_t | len | ||
) |
Synchronize a segment of memory mapped from a segment fetch.
address | memory address to update. |
len | size of segment. |
|
inlineinherited |
|
inherited |
Tries to lock the mutex for the current thread.
Behaves like enterMutex , except that it doesn't block the calling thread if the mutex is already locked by another thread.
void MappedFile::unlock | ( | void | ) |
Unlock a locked mapped portion of a file.
void MappedFile::update | ( | size_t | offset = 0 , |
size_t | len = 0 |
||
) |
Map a portion of the memory mapped from the file back to the file and do not wait for completion.
This is useful when mapping a database file and updating a single record.
offset | offset into the mapped region of memory. |
len | length of partial region (example, record length). |
void MappedFile::update | ( | char * | address, |
size_t | len | ||
) |
Update a mapped region back to disk as specified by address and length.
address | address of segment. |
len | length of segment. |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
struct { ... } RandomFile::flags |