Files
iostreams/doc/classes/file_descriptor.html
Jonathan Turkanis d7ab2136fe misc
[SVN r30015]
2005-07-12 16:57:05 +00:00

263 lines
14 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 Descriptors</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 handles or file descriptors. These <A HREF="../guide/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 <A HREF="../guide/buffering.html">buffering</A> is provded by the Boost Iostreams library.
<LI CLASS="square">There is no automatic line-ending conversion.
<LI CLASS="square">Wide-character streams are not supported.
</UL>
<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>
The classes <CODE>file_descriptor</CODE> supports 64-bit seek offsets whenever they are supported by the underlying operating system or runtime library. Currently, file descriptor Devices may not work corectly with file descriptors opened in non-blocking mode.
</P>
<P>
Line-ending conversion can be provided, if desired, using the class <A HREF="newline_filter.html"><CODE>newline_filter</CODE></A>. Wide-character versions of the file descriptor Devices may be defined as follows, using the template <A HREF="code_converter.html"><CODE>code_converter</CODE></A>:
<PRE CLASS="broken_ie"> <SPAN CLASS="preprocessor">#include</SPAN> <A CLASS="header" HREF="../../../../boost/iostreams/code_converter.hpp"><SPAN CLASS="literal">&lt;boost/iostreams/code_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>
<SPAN CLASS='keyword'>typedef</SPAN> code_converter&lt;file_descriptor_source&gt; wfile_descriptor_source;
<SPAN CLASS='keyword'>typedef</SPAN> code_converter&lt;file_descriptor_sink&gt; wfile_descriptor_sink;</PRE>
</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>:
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='keyword'>char</SPAN> char_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
file_descriptor_source( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
file_descriptor_source( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_source( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
};
} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></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">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
file_descriptor_source( <SPAN CLASS="keyword">int </SPAN>fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_source( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The first 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></A>
</P>
<P>
The second member constructs a <CODE>file_descriptor_source</CODE> to access the file with the given operating system or runtime-library file descriptor. If the second argument is <CODE>true</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed &#8212; or one of its copies &#8212; is closed.
</P>
<P>
The third member is the same as the second, except that it accepts a Windows file handle instead of a file descriptor. If the second argument is <CODE>true</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed &#8212; or one of its copies &#8212; is closed.
</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>:
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='keyword'>char</SPAN> char_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
file_descriptor_sink( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
file_descriptor_sink( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_sink( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
};
} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></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">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
file_descriptor_sink( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_sink( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The first 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></A>
</P>
<P>
The second member constructs a <CODE>file_descriptor_sink</CODE> to access the file with the given operating system or runtime-library 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.
</P>
<P>
The third member is the same as the second, except that it accepts a Windows file handle instead of a 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.
</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>:
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='keyword'>char</SPAN> char_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
file_descriptor( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
file_descriptor( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
};
} } <SPAN CLASS='comment'>// End namespace boost::io</SPAN></PRE>
<A NAME="file_descriptor_constructor"></A>
<H4><CODE>file_descriptor::file_descriptor</CODE></H4>
<PRE CLASS="broken_ie"> file_descriptor( <SPAN CLASS="keyword">const</SPAN> std::string& pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
file_descriptor( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The first 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></A>
</P>
<P>
The second member constructs a <CODE>file_descriptor</CODE> to access the file with the given operating system or runtime-library 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.
</P>
<P>
The third member is the same as the second, except that it accepts a Windows file handle instead of a 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.
</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>