|
|
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:
fname | path name of disk file to open. |
access | access 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:
f | reference 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:
buf | pointer to data to write to the file. |
len | number 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:
pos | offset to portion of file to read. |
buf | pointer to memory to read data into. |
len | number 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:
pos | offset to portion of file to write. |
buf | pointer to memory to write data from. |
len | number 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:
pos | offset to portion of file that was locked. |
len | number of bytes originally requested. |
Returns: 0 on success, -1 on error.