Files
iostreams/doc/classes/file_descriptor.html
Jonathan Turkanis c0564c3c7c initial commitment
[SVN r26900]
2005-01-28 23:54:41 +00:00

213 lines
11 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>File Descriptor Devices</TITLE>
<LINK REL='stylesheet' HREF='../../../../boost.css'>
<LINK REL='stylesheet' HREF='../theme/iostreams.css'>
<STYLE> H3 CODE { font-size: 110% } </STYLE>
</HEAD>
<BODY>
<!-- Begin Banner -->
<H1 CLASS='title'>File Descriptor Devices</H1>
<HR CLASS='banner'>
<!-- End Banner -->
<DL class='page-index'>
<DT><A href='#overview'>Overview</A></DT>
<DT><A href='#acknowledgments'>Acknowledments</A></DT>
<DT><A href='#installation'>Installation</A></DT>
<DT><A href='#headers'>Headers</A></DT>
<DT><A href='#reference'>Reference</A>
<UL>
<LI CLASS='square'><A href='#file_descriptor_source'>Class <CODE>file_descriptor_source</CODE></A></LI>
<LI CLASS='square'><A href='#file_descriptor_sink'>Class <CODE>file_descriptor_sink</CODE></A></LI>
<LI CLASS='square'><A href='#file_descriptor'>Class <CODE>file_descriptor</CODE></A></LI>
</UL>
</DT>
</DL>
<HR>
<A NAME='overview'>
<H2>Overview</H2>
<P>
The classes <CODE>file_descriptor_source</CODE>, <CODE>file_descriptor_sink</CODE> and <CODE>file_descriptor</CODE> provide file access via operating system file descriptors. These <A HREF="../concepts.html#device_concepts">Devices</A> behave much like the <A HREF="file.html">File Wrappers</A> <CODE>basic_file_source</CODE>, <CODE>basic_file_sink</CODE> and <CODE>basic_file</CODE>, with the following important differences:
</P>
<UL>
<LI CLASS='square'>A file descriptor Device may be constructed from a file descriptor which is already open.
<LI CLASS='square'>The only buffering is provded by the Boost Iostreams Library.
<LI CLASS='square'>There is no automatic line-endings conversion.
<LI CLASS='square'>Wide-character streams are not supported.
</UL>
<P>
Line-ending conversion is available using the <A HREF='newline_filter.html'>Newline Filters</A>. Wide-character versions of the file descriptor Devices may be defined as follows, using the template <A HREF='converter.html'><CODE>converter</CODE></A>:
<PRE CLASS='broken_ie'> <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/converter.hpp'><SPAN CLASS="literal">&lt;boost/iostreams/converter.hpp&gt;</SPAN></A>
<SPAN CLASS="preprocessor">#include</SPAN> <A CLASS='header' HREF='../../../../boost/iostreams/device/file_descriptor.hpp'><SPAN CLASS="literal">&lt;boost/iostreams/maped_file.hpp&gt;</SPAN></A>
typedef converter&lt;file_descriptor_source&gt; <SPAN CLASS="defined">wfile_descriptor_source</SPAN>;
typedef converter&lt;file_descriptor_sink&gt; <SPAN CLASS="defined">wfile_descriptor_sink</SPAN>;</PRE>
</P>
<P>
When a file descriptor Device is copied, the result represents the same underlying file descriptor. The underlying file descriptor is <I>not</I> duplicated.
</P>
<P>
Currently, file descriptor Devices do not work corectly with file descriptors opened in non-blocking mode.
</P>
<A NAME='acknowledgments'>
<H2>Acknowledgments</H2>
<P>
The file descriptor Devices are based on work of Nicolai Josuttis (<A CLASS='bib_ref' HREF='../bibliography.html#josuttis1'>[Josuttis1]</A> <I>pp.</I> 672-3 and <A CLASS='bib_ref' HREF='../bibliography.html#josuttis2'>[Josuttis2]</A>).
</P>
<A NAME='installation'>
<H2>Installation</H2>
<P>
The file descriptor Devices depends on the source file <A CLASS='header' HREF='../../src/file_descriptor.cpp'><CODE>&lt;libs/iostreams/src/file_descriptor.cpp&gt;</CODE></A>, which makes use of Windows or POSIX headers depending on the user's operating system. For installation instructions see <A HREF='../installation.html'>Installation</A>.
</P>
<A NAME='headers'>
<H2>Headers</H2>
<DL class='page-index'>
<DT><A CLASS='header' HREF='../../../../boost/iostreams/device/file_descriptor.hpp'><CODE>&lt;boost/iostreams/device/file_descriptor.hpp&gt;</CODE></A></DT>
</DL>
<A NAME='reference'>
<H2>Reference</H2>
<A NAME='file_descriptor_source'>
<H3>Class <CODE>file_descriptor_source</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF='../concepts/source.html'>Source</A> providing read-only access to a file through an operating system file descriptor.</P>
<H4>Synopsis</H4>
<PRE CLASS='broken_ie'><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
<SPAN CLASS="keyword">class</SPAN> file_descriptor_source : <SPAN CLASS="keyword">public</SPAN> <A CLASS="documented" HREF="device.html#synopsis">source</A> { <SPAN CLASS="comment">// Exposition only</SPAN>
<SPAN CLASS="keyword">public</SPAN>:
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN> );
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
};
} } // End namespace boost::io</PRE>
<A NAME='file_descriptor_source_ctor'></A>
<H4><CODE>file_descriptor_source::file_descriptor_source</CODE></H4>
<A NAME='file_descriptor_source_ctor'></A>
<PRE CLASS='broken_ie'> file_descriptor_source( <SPAN CLASS="keyword">int </SPAN>fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN>);
file_descriptor_source( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in );</PRE>
<P>
The first member constructs a <CODE>file_descriptor_source</CODE> to access the file with the given operating system file descriptor. If the second argument is <CODE>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor_source</CODE> &#8212; or one of its copies &#8212; is closed. The second member constructs a <CODE>file_descriptor_source</CODE> to access the file with the given pathname. The parameter <CODE>mode</CODE> has the same interpretation as <CODE>(mode | std::ios_base::in)</CODE> in <CODE>std::basic_filebuf::open</CODE>.<A CLASS='footnote_ref' NAME='note_1_ref' HREF='#note_1'><SUP>[1]</SUP>
</P>
<A NAME='file_descriptor_sink'>
<H3>Class <CODE>file_descriptor_sink</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF='../concepts/sink.html'>Sink</A> providing write-only access to a file through an operating system file descriptor.
<H4>Synopsis</H4>
<PRE CLASS='broken_ie'><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
<SPAN CLASS="keyword">class</SPAN> file_descriptor_sink : <SPAN CLASS="keyword">public</SPAN> <A CLASS="documented" HREF="device.html#synopsis">sink</A> { <SPAN CLASS="comment">// Exposition only</SPAN>
<SPAN CLASS="keyword">public</SPAN>:
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN> );
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
};
} } // End namespace boost::io</PRE>
<A NAME='file_descriptor_sink_ctor'></A>
<H4><CODE>file_descriptor_sink::file_descriptor_sink</CODE></H4>
<PRE CLASS='broken_ie'> file_descriptor_sink( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN> );
file_descriptor_sink( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::out );</PRE>
<P>
The first member constructs a <CODE>file_descriptor_sink</CODE> to access the file with the given operating system file descriptor. If the second argument is <CODE>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor_sink</CODE> &#8212; or one of its copies &#8212; is closed. The second member constructs a <CODE>file_descriptor_sink</CODE> to access the file with the given pathname. The parameter <CODE>mode</CODE> has the same interpretation as <CODE>(mode | std::ios_base::out)</CODE> in <CODE>std::basic_filebuf::open</CODE>.<A CLASS='footnote_ref' NAME='note_1_ref' HREF='#note_1'><SUP>[1]</SUP>
</P>
<A NAME='file_descriptor'>
<H3>Class <CODE>file_descriptor</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF='../concepts/seekable_device.html'>SeekableDevice</A> providing read-write access to a file through an operating system file descriptor.
<H4>Synopsis</H4>
<PRE CLASS='broken_ie'><SPAN CLASS="keyword">namespace</SPAN> boost { <SPAN CLASS="keyword">namespace</SPAN> iostreams {
<SPAN CLASS="keyword">class</SPAN> file_descriptor : <SPAN CLASS="keyword">public</SPAN> <A CLASS="documented" HREF="device.html">Device</A>&lt;seekable&gt; { <SPAN CLASS="comment">// Exposition only</SPAN>
<SPAN CLASS="keyword">public</SPAN>:
<A CLASS="documented" HREF="#file_descriptor_ctor">file_descriptor</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN> );
<A CLASS="documented" HREF="#file_descriptor_ctor">file_descriptor</A>( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
};
} } // End namespace boost::io</PRE>
<A NAME='file_descriptor_constructor'></A>
<H4><CODE>file_descriptor::file_descriptor</CODE></H4>
<PRE CLASS='broken_ie'> file_descriptor( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close = <SPAN CLASS="keyword">false</SPAN> );
file_descriptor( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );</PRE>
<P>
The first member constructs a <CODE>file_descriptor</CODE> to access the file with the given operating system file descriptor. If the second argument is <CODE>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor</CODE> &#8212; or one of its copies &#8212; is closed. The second member constructs a <CODE>file_descriptor</CODE> to access the file with the given pathname. The parameter <CODE>mode</CODE> has the same interpretation as in <CODE>std::basic_filebuf::open</CODE>.<A CLASS='footnote_ref' NAME='note_1_ref' HREF='#note_1'><SUP>[1]</SUP>
</P>
<!-- Begin Footnotes -->
<HR>
<P>
<A CLASS='footnote_ref' NAME='note_1' HREF='#note_1_ref'><SUP>[1]</SUP></A><A CLASS='bib_ref' HREF='../bibliography.html#iso'>[I<SPAN STYLE='font-size:80%'>SO</SPAN>]</A>, Table 92.
</P>
<!-- End Footnotes -->
<!-- Begin Footer -->
<HR>
<P CLASS='copyright'>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
20 May, 2004
<!--webbot bot="Timestamp" endspan i-checksum="38504" -->
</P>
<P CLASS='copyright'>&copy; Copyright Jonathan Turkanis, 2004</P>
<P CLASS='copyright'>
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF='http://www.boost.org/LICENSE_1_0.txt'>http://www.boost.org/LICENSE_1_0.txt</A>)
</P>
<!-- End Footer -->
</BODY>