class LockedFile

shared file access between different processes. More...

Definition#include <file.h>
InheritsFile [protected]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members


Detailed Description

Locked files are presumed to be shared between different processes. File locks are used to protect file access and specifically defined operations which must occur exclusivily by a single process, such as for logical record locks in a database. Record locking is assumed to be a blocking operation.

LockedFile (const char *fname, int access)

Open an existing and named data file that may be shared by multiple processes. Throw an exception if the file doesn't exist or cannot be accessed.

Parameters:
fnamepath name of disk file to open.
accessaccess mode (read, write, or rdwr) to use.

See also: File

LockedFile (const LockedFile &f)

Duplicate an existing locked file's descriptor, but do not duplicate any outstanding locks.

Parameters:
freference to another LockedFile.

~LockedFile ()

Release the locked file and any locks held by this object.

int Append (void *buf, size_t len)

Recieve a lock from the end of the current file to inf and when successful write the specified data to the end. Upon completion, release the file lock.

Parameters:
bufpointer to data to write to the file.
lennumber of bytes to write.

Returns: number of bytes written on success, -1 on error.

Reimplemented from File

int Request (pos_t pos, void *buf, size_t len)

Request a lock for a portion of the datafile and then read the exclusivily locked portion of the file into memory.

Parameters:
posoffset to portion of file to read.
bufpointer to memory to read data into.
lennumber of bytes to read.

Returns: number of bytes read on success, -1 on error.

int Update (pos_t pos, void *buf, size_t len)

Copy a presumably modified memory block back to a locked portion of a file as retrieved from a previous request, and then clear the file lock so that another process may now access that region. No check is made to assure the Update actually matches a previous Request.

Parameters:
posoffset to portion of file to write.
bufpointer to memory to write data from.
lennumber of bytes to write.

Returns: number of bytes written on success, -1 on error.

int Clear (pos_t pos, size_t len)

Release a lock held from a request without modifying any data in the file so that another process may now access the locked region. No check is made to assure the Clear actually matches an existing Request.

Parameters:
posoffset to portion of file that was locked.
lennumber of bytes originally requested.

Returns: 0 on success, -1 on error.