iostreams/doc/classes/file_descriptor.html

529 lines
30 KiB
HTML

<!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"></A>
<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"></A>
<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"></A>
<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"></A>
<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"></A>
<H2>Reference</H2>
<A NAME="file_descriptor_source"></A>
<H3>Class <CODE>file_descriptor_source</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF="../concepts/device.html">SeekableSource</A> and <A HREF="../concepts/closable.html">Closable</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">enum</SPAN> file_descriptor_flags {
never_close_handle,
close_handle
};
<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> handle_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>();
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</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_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
handle_type <A CLASS="documented" HREF="#file_descriptor_source_handle">handle</A>() <SPAN CLASS="keyword">const</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>
<PRE CLASS="broken_ie"> file_descriptor_source();
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
file_descriptor_source( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
file_descriptor_source( <SPAN CLASS="keyword">int </SPAN>fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_source( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
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'>// Deprecated, 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 an empty <CODE>file_descriptor_source</CODE>.
</P>
<P>
The second member constructs a <CODE>file_descriptor_source</CODE> to access the file with the given pathname. <CODE>Path</CODE> should be either a string or a Boost.Filesystem path. 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 third 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>close_handle</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
If the second argument is <CODE>close_handle</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The deprecated members are there to provide backwards compatability with old versions.
To use them you need to define <CODE>BOOST_IOSTREAMS_USE_DEPRECATED</CODE>.
The descriptor is always closed by <CODE>close</CODE> but only closed in destructors if <CODE>close_on_exit</CODE> is <CODE>true</CODE>.
</P>
<A NAME="file_descriptor_source_open"></A>
<H4><CODE>file_descriptor_source::open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in );
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The parameters of <CODE>open</CODE> the same as those of the corresponding constructors.
If the file descriptor already holds a file, it'll be closed
(unless opened or constructed with <CODE>never_close_handle</CODE>).
</P>
<A NAME="file_descriptor_source_is_open"></A>
<H4><CODE>file_descriptor_source::is_open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns <CODE>true</CODE> if the underlying file was opened successfully.</P>
<A NAME="file_descriptor_source_handle"></A>
<H4><CODE>file_descriptor_source::handle</CODE></H4>
<PRE CLASS="broken_ie"> handle_type handle() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns the underlying OS file descriptor. On Windows, this is a <CODE>HANDLE</CODE>. On other systems, it is an <CODE><SPAN CLASS="keyword">int</SPAN></CODE>.</P>
<A NAME="file_descriptor_sink"></A>
<H3>Class <CODE>file_descriptor_sink</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF="../concepts/device.html">SeekableSink</A> and <A HREF="../concepts/closable.html">Closable</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">enum</SPAN> file_descriptor_flags {
never_close_handle,
close_handle
};
<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> handle_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>();
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</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_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_sink_ctor">file_descriptor_sink</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
handle_type <A CLASS="documented" HREF="#file_descriptor_sink_handle">handle</A>() <SPAN CLASS="keyword">const</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">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
file_descriptor_sink( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
file_descriptor_sink( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor_sink( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
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'>// Deprecated, 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 an empty <CODE>file_descriptor_sink</CODE>.
</P>
<P>
The second member constructs a <CODE>file_descriptor_sink</CODE> to access the file with the given pathname. <CODE>Path</CODE> should be either a string or a Boost.Filesystem path. 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_ref2" HREF="#note_1"><SUP>[1]</SUP></A>
</P>
<P>
The third 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>close_handle</CODE>, the file descriptor is closed when the <CODE>file_descriptor_sink</CODE> being constructed &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
If the second argument is <CODE>close_handle</CODE>, the file descriptor is closed when the <CODE>file_descriptor_sink</CODE> being constructed &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The deprecated members are there to provide backwards compatability with old versions.
To use them you need to define <CODE>BOOST_IOSTREAMS_USE_DEPRECATED</CODE>.
The descriptor is always closed by <CODE>close</CODE> but only closed in destructors if <CODE>close_on_exit</CODE> is <CODE>true</CODE>.
</P>
<A NAME="file_descriptor_sink_open"></A>
<H4><CODE>file_descriptor_sink::open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::out );
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The parameters of <CODE>open</CODE> the same as those of the corresponding constructors.
If the file descriptor already holds a file, it'll be closed
(unless opened or constructed with <CODE>never_close_handle</CODE>).
</P>
<A NAME="file_descriptor_sink_is_open"></A>
<H4><CODE>file_descriptor_sink::is_open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns <CODE>true</CODE> if the underlying file was opened successfully.</P>
<A NAME="file_descriptor_sink_handle"></A>
<H4><CODE>file_descriptor_sink::handle</CODE></H4>
<PRE CLASS="broken_ie"> handle_type handle() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns the underlying OS file descriptor. On Windows, this is a <CODE>HANDLE</CODE>. On other systems, it is an <CODE><SPAN CLASS="keyword">int</SPAN></CODE>.</P>
<A NAME="file_descriptor"></A>
<H3>Class <CODE>file_descriptor</CODE></H3>
<H4>Description</H4>
<P>Model of <A HREF="../concepts/seekable_device.html">SeekableDevice</A> and <A HREF="../concepts/closable.html">Closable</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">enum</SPAN> file_descriptor_flags {
never_close_handle,
close_handle
};
<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> handle_type;
<SPAN CLASS='keyword'>typedef</SPAN> <SPAN CLASS='omitted'>[implementation-defined]</SPAN> category;
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>();
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS="keyword">bool</SPAN> <A CLASS="documented" HREF="#file_descriptor_is_open">is_open</A>() <SPAN CLASS="keyword">const</SPAN>;
handle_type <A CLASS="documented" HREF="#file_descriptor_handle">handle</A>() <SPAN CLASS="keyword">const</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">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
file_descriptor( <SPAN CLASS="keyword">const</SPAN> Path&amp; 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">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
file_descriptor( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
file_descriptor( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, 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 an empty <CODE>file_descriptor</CODE>.
</P>
<P>
The second member constructs a <CODE>file_descriptor</CODE> to access the file with the given pathname. <CODE>Path</CODE> should be either a string or a Boost.Filesystem path. The parameter <CODE>mode</CODE> has the same interpretation as in <CODE>std::basic_filebuf::open</CODE>.<A CLASS="footnote_ref" NAME="note_1_ref3" HREF="#note_1"><SUP>[1]</SUP></A>
</P>
<P>
The third 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>close_handle</CODE>, the file descriptor is closed when the <CODE>file_descriptor</CODE> being constructed &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
If the second argument is <CODE>close_handle</CODE>, the file descriptor is closed when the new <CODE>file_descriptor</CODE> &#8212; or one of its copies &#8212; is closed or destructed.
</P>
<P>
The deprecated members are there to provide backwards compatability with old versions.
To use them you need to define <CODE>BOOST_IOSTREAMS_USE_DEPRECATED</CODE>.
The descriptor is always closed by <CODE>close</CODE> but only closed in destructors if <CODE>close_on_exit</CODE> is <CODE>true</CODE>.
</P>
<A NAME="file_descriptor_open"></A>
<H4><CODE>file_descriptor::open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">template</SPAN>&lt;<SPAN CLASS="keyword">typename</SPAN> Path&gt;
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path&amp; pathname,
std::ios_base::open_mode mode =
std::ios_base::in | std::ios_base::out );
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
<SPAN CLASS='comment'>// Deprecated</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
<SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
<SPAN CLASS="keyword">void</SPAN> open( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
<P>
The parameters of <CODE>open</CODE> the same as those of the corresponding constructors.
If the file descriptor already holds a file, it'll be closed
(unless opened or constructed with <CODE>never_close_handle</CODE>).
</P>
<A NAME="file_descriptor_is_open"></A>
<H4><CODE>file_descriptor::is_open</CODE></H4>
<PRE CLASS="broken_ie"> <SPAN CLASS="keyword">bool</SPAN> is_open() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns <CODE><SPAN CLASS="keyword">true</SPAN></CODE> if the underlying file was opened successfully.</P>
<A NAME="file_descriptor_handle"></A>
<H4><CODE>file_descriptor::handle</CODE></H4>
<PRE CLASS="broken_ie"> handle_type handle() <SPAN CLASS="keyword">const</SPAN>;</PRE>
<P>Returns the underlying OS file descriptor. On Windows, this is a <CODE>HANDLE</CODE>. On other systems, it is an <CODE><SPAN CLASS="keyword">int</SPAN></CODE>.</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">&copy; Copyright 2008 <a href="http://www.coderage.com/" target="_top">CodeRage, LLC</a><br/>&copy; Copyright 2004-2007 <a href="https://www.boost.org/users/people/jonathan_turkanis.html" target="_top">Jonathan Turkanis</a></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>