1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
<HTML><HEAD><TITLE>SharedFile Class</TITLE></HEAD>
<BODY bgcolor="#ffffff">
<H1>SharedFile Class Reference</H1>
<p>
[<A HREF="index.html">APE Index</A>] [<A HREF="hier.html">APE Hierarchy</A>]
[<A HREF="header-list.html">Headers</A>]
</p>
<HR>
<P>Shared concurrent file access from multiple threads. <a href="#short">More...</a></P>
<P>
<code>
#include <<a href="file-h.html">file.h</a>>
</code>
</P>
<P>
Inherits: <a href="File.html">File</a>, <a href="Mutex.html">Mutex</a>
<P>
<H2>Public Members</H2>
<UL>
<LI> <b><a href="#ref0">SharedFile</a></b> (const char *fname, int access, int perm)
</LI>
<LI> <b><a href="#ref1">SharedFile</a></b> (const char *fname, int access)
</LI>
<LI> <b><a href="#ref2">SharedFile</a></b> (const SharedFile &f)
</LI>
<LI> <b><a href="#ref3">SharedFile</a></b> (int fd)
</LI>
<LI> <b><a href="#ref4">~SharedFile</a></b> ()
</LI>
<LI>int <b><a href="#ref5">Append</a></b> (void *buf, size_t len)
</LI>
<LI>int <b><a href="#ref6">Read</a></b> (pos_t pos, void *buf, size_t len)
</LI>
<LI>int <b><a href="#ref7">Write</a></b> (pos_t pos, void *buf, size_t len)
</LI>
<LI>SharedFile& <b><a name="ref8">operator=</a></b> (SharedFile &f)
</LI>
<LI>friend inline int <b><a name="ref9">read</a></b> (SharedFile &f, pos_t pos, void *buf, size_t len)
</LI>
<LI>friend inline int <b><a name="ref10">write</a></b> (SharedFile &f, pos_t pos, void *buf, size_t len)
</LI>
<LI>friend inline int <b><a name="ref11">append</a></b> (SharedFile &f, void *buf, size_t len)
</LI>
</UL>
<HR>
<H2><a name="short">Detailed Description</a></H2>
<P>
Locked files provide clean access to a database file that is shared
between multiple processes via file locking. A seperate and more
efficient methodology is provided here to enable multiple threads to
access the same file descriptor concurrently. While shared files do
not include thread exclusive file region locking, such locking can be
established with in memory based tables rather than kernel file locks
for speed if needed.
</P><HR>
<H3><b> <a name="ref0"></a><a name="SharedFile">SharedFile</a>(const char *fname, int access, int perm) </b><code>[public]</code></H3>
<p>Create a new disk file that will be shared between multiple
threads. A file name, access mode, and file permissions to
use when creating a new file are specified. On failure an
exception is thrown.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
access</td><td align="left" valign="top">
file access mode.</td></tr>
<tr><td align="left" valign="top">
perm</td><td align="left" valign="top">
file permission to assign when creating a new file.</td></tr>
<tr><td align="left" valign="top">
fname</td><td align="left" valign="top">
path name of disk file to open or create.</td></tr>
</table>
</dl>
<dl><dt><b>See Also</b>:<dd><a href="File.html#File">File::File</a></dl>
<H3><b> <a name="ref1"></a><a name="SharedFile">SharedFile</a>(const char *fname, int access) </b><code>[public]</code></H3>
<p>Open an existing disk file for shared access between multiple
threads. A file name and file access mode must be specified.
If the file does not exist or cannot be opened, an exception is
thrown.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
access</td><td align="left" valign="top">
file access mode.</td></tr>
<tr><td align="left" valign="top">
fname</td><td align="left" valign="top">
path name of disk file to open.</td></tr>
</table>
</dl>
<H3><b> <a name="ref2"></a><a name="SharedFile">SharedFile</a>(const <a href="SharedFile.html">SharedFile</a> &f) </b><code>[public]</code></H3>
<p>Open a copy of an existing "File" through a duplicate object for
shared access from multiple threads. This essentially uses the
Posix dup() call to duplicate the file descriptor involved.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
f</td><td align="left" valign="top">
an existing File class to duplicate from.</td></tr>
</table>
</dl>
<H3><b> <a name="ref3"></a><a name="SharedFile">SharedFile</a>(int fd) </b><code>[public]</code></H3>
<p>Create a shared file "class" to reference an existing and already
open file descriptor from multiple threads. This is kind of like
"fdopen" in purpose, and simply allows any existing file descriptor
to be manipulated by the thread shared methods.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
fd</td><td align="left" valign="top">
an existing and already open file descriptor.</td></tr>
</table>
</dl>
<H3><b> <a name="ref4"></a><a name="~SharedFile">~SharedFile</a>() </b><code>[public]</code></H3>
<p>Close the existing shared file object and release any used
resources.
</p>
<H3><b>int <a name="ref5"></a><a name="Append">Append</a>(void *buf, size_t len) </b><code>[public]</code></H3>
<p>Write data to the end of a specified share file exclusivily.
The mutex lock is used to assure the write operation is not
interfered with by other threads until it completes.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
buf</td><td align="left" valign="top">
pointer to data to write to the file.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to write.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes written on success, -1 on failure.</dl>
<H3><b>int <a name="ref6"></a><a name="Read">Read</a>(pos_t pos, void *buf, size_t len) </b><code>[public]</code></H3>
<p>Read data from a specified file offset exclusivily. The Mutex
lock is used to assure the read operation can complete without
interference by other threads. While the current file offset
must be specified and tracked seperately by each thread on it's
own, an enhanced version may soon use a ThreadKey for this purpose.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
pos</td><td align="left" valign="top">
file offset to start read from file.</td></tr>
<tr><td align="left" valign="top">
buf</td><td align="left" valign="top">
pointer to store data read from file.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to read.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes read on success, -1 on error.</dl>
<H3><b>int <a name="ref7"></a><a name="Write">Write</a>(pos_t pos, void *buf, size_t len) </b><code>[public]</code></H3>
<p>Write data to a specified file offset exclusivily. The Mutex
lock is used to assure the write operation can complete without
interference by other threads. While the current file offset
must be specified and tracked seperately by each thread on it's
own, an enhanced version may soon use a ThreadKey for this purpose.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
pos</td><td align="left" valign="top">
file offset to start file write.</td></tr>
<tr><td align="left" valign="top">
buf</td><td align="left" valign="top">
pointer to data to write to the file.</td></tr>
<tr><td align="left" valign="top">
len</td><td align="left" valign="top">
number of bytes to write.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes written on success, -1 on error.</dl>
<HR>
<TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top">
<UL><LI><I>Author</I>: David Sugar <dyfet@ostel.com> </LI>
<LI>Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
</LI>
</UL></TD><TD ALIGN="RIGHT" VALIGN="TOP">
<b>K</b><i>doc</i>
</TD>
</TR></TABLE></BODY></HTML>
|