1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <TITLE>File Descriptor Devices
</TITLE>
5 <LINK REL=
"stylesheet" HREF=
"../../../../boost.css">
6 <LINK REL=
"stylesheet" HREF=
"../theme/iostreams.css">
7 <STYLE> H3 CODE { font-size:
110% }
</STYLE>
13 <H1 CLASS=
"title">File Descriptors
</H1>
18 <DL class=
"page-index">
19 <DT><A href=
"#overview">Overview
</A></DT>
20 <DT><A href=
"#acknowledgments">Acknowledments
</A></DT>
21 <DT><A href=
"#installation">Installation
</A></DT>
22 <DT><A href=
"#headers">Headers
</A></DT>
23 <DT><A href=
"#reference">Reference
</A>
25 <LI CLASS=
"square"><A href=
"#file_descriptor_source">Class
<CODE>file_descriptor_source
</CODE></A></LI>
26 <LI CLASS=
"square"><A href=
"#file_descriptor_sink">Class
<CODE>file_descriptor_sink
</CODE></A></LI>
27 <LI CLASS=
"square"><A href=
"#file_descriptor">Class
<CODE>file_descriptor
</CODE></A></LI>
34 <A NAME=
"overview"></A>
38 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:
41 <LI CLASS=
"square">A file descriptor Device may be constructed from a file descriptor which is already open.
42 <LI CLASS=
"square">The only
<A HREF=
"../guide/buffering.html">buffering
</A> is provded by the Boost Iostreams library.
43 <LI CLASS=
"square">There is no automatic line-ending conversion.
44 <LI CLASS=
"square">Wide-character streams are not supported.
48 When a file descriptor Device is copied, the result represents the same underlying file descriptor. The underlying file descriptor is
<I>not
</I> duplicated.
52 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.
56 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>:
57 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/code_converter.hpp"><SPAN CLASS=
"literal"><boost/iostreams/code_converter.hpp
></SPAN></A>
58 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/device/file_descriptor.hpp"><SPAN CLASS=
"literal"><boost/iostreams/maped_file.hpp
></SPAN></A>
60 <SPAN CLASS='keyword'
>typedef
</SPAN> code_converter
<file_descriptor_source
> wfile_descriptor_source;
61 <SPAN CLASS='keyword'
>typedef
</SPAN> code_converter
<file_descriptor_sink
> wfile_descriptor_sink;
</PRE>
64 <A NAME=
"acknowledgments"></A>
65 <H2>Acknowledgments
</H2>
68 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>).
71 <A NAME=
"installation"></A>
75 The file descriptor Devices depends on the source file
<A CLASS=
"header" HREF=
"../../src/file_descriptor.cpp"><CODE><libs/iostreams/src/file_descriptor.cpp
></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>.
78 <A NAME=
"headers"></A>
81 <DL class=
"page-index">
82 <DT><A CLASS=
"header" HREF=
"../../../../boost/iostreams/device/file_descriptor.hpp"><CODE><boost/iostreams/device/file_descriptor.hpp
></CODE></A></DT>
86 <A NAME=
"reference"></A>
89 <A NAME=
"file_descriptor_source"></A>
90 <H3>Class
<CODE>file_descriptor_source
</CODE></H3>
94 <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>
98 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
100 <SPAN CLASS=
"keyword">enum
</SPAN> file_descriptor_flags {
105 <SPAN CLASS=
"keyword">class
</SPAN> file_descriptor_source {
106 <SPAN CLASS=
"keyword">public
</SPAN>:
107 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
108 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> handle_type;
109 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
110 <A CLASS=
"documented" HREF=
"#file_descriptor_source_ctor">file_descriptor_source
</A>();
111 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
112 <A CLASS=
"documented" HREF=
"#file_descriptor_source_ctor">file_descriptor_source
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
113 std::ios_base::open_mode mode =
115 <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> );
117 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
118 <A CLASS=
"documented" HREF=
"#file_descriptor_source_ctor">file_descriptor_source
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
120 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
121 <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> );
123 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
124 <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> );
126 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
127 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_source_open">open
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
128 std::ios_base::open_mode mode =
130 <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> );
132 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
133 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_source_open">open
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
135 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
136 <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> );
138 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
139 <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> );
141 <SPAN CLASS=
"keyword">bool
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_source_is_open">is_open
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
143 handle_type
<A CLASS=
"documented" HREF=
"#file_descriptor_source_handle">handle
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
146 } }
<SPAN CLASS='comment'
>// End namespace boost::io
</SPAN></PRE>
148 <A NAME=
"file_descriptor_source_ctor"></A>
149 <H4><CODE>file_descriptor_source::file_descriptor_source
</CODE></H4>
151 <PRE CLASS=
"broken_ie"> file_descriptor_source();
152 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
153 file_descriptor_source(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
154 std::ios_base::open_mode mode =
156 file_descriptor_source(
<SPAN CLASS=
"keyword">int
</SPAN>fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
158 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
159 file_descriptor_source( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
161 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
162 file_descriptor_source(
<SPAN CLASS=
"keyword">int
</SPAN>fd,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
164 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
165 file_descriptor_source( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
167 The first member constructs an empty
<CODE>file_descriptor_source
</CODE>.
171 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>
175 The third member constructs a
<CODE>file_descriptor_source
</CODE> to access the file with the given operating system or runtime-library file descriptor.
176 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the
<CODE>file_descriptor_source
</CODE> being constructed
— or one of its copies
— is closed or destructed.
180 The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
181 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the
<CODE>file_descriptor_source
</CODE> being constructed
— or one of its copies
— is closed or destructed.
185 The deprecated members are there to provide backwards compatability with old versions.
186 To use them you need to define
<CODE>BOOST_IOSTREAMS_USE_DEPRECATED
</CODE>.
187 The descriptor is always closed by
<CODE>close
</CODE> but only closed in destructors if
<CODE>close_on_exit
</CODE> is
<CODE>true
</CODE>.
190 <A NAME=
"file_descriptor_source_open"></A>
191 <H4><CODE>file_descriptor_source::open
</CODE></H4>
193 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
194 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
195 std::ios_base::open_mode mode =
197 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
199 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
200 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
202 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
203 <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> );
205 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
206 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
209 The parameters of
<CODE>open
</CODE> the same as those of the corresponding constructors.
210 If the file descriptor already holds a file, it'll be closed
211 (unless opened or constructed with
<CODE>never_close_handle
</CODE>).
214 <A NAME=
"file_descriptor_source_is_open"></A>
215 <H4><CODE>file_descriptor_source::is_open
</CODE></H4>
217 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">bool
</SPAN> is_open()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
219 <P>Returns
<CODE>true
</CODE> if the underlying file was opened successfully.
</P>
221 <A NAME=
"file_descriptor_source_handle"></A>
222 <H4><CODE>file_descriptor_source::handle
</CODE></H4>
224 <PRE CLASS=
"broken_ie"> handle_type handle()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
226 <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>
228 <A NAME=
"file_descriptor_sink"></A>
229 <H3>Class
<CODE>file_descriptor_sink
</CODE></H3>
233 <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.
237 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
239 <SPAN CLASS=
"keyword">enum
</SPAN> file_descriptor_flags {
244 <SPAN CLASS=
"keyword">class
</SPAN> file_descriptor_sink {
245 <SPAN CLASS=
"keyword">public
</SPAN>:
246 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
247 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> handle_type;
248 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
249 <A CLASS=
"documented" HREF=
"#file_descriptor_sink_ctor">file_descriptor_sink
</A>();
250 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
251 <A CLASS=
"documented" HREF=
"#file_descriptor_sink_ctor">file_descriptor_sink
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
252 std::ios_base::open_mode mode =
253 std::ios_base::out );
254 <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> );
256 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
257 <A CLASS=
"documented" HREF=
"#file_descriptor_sink_ctor">file_descriptor_sink
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
259 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
260 <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> );
262 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
263 <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> );
265 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
266 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_sink_open">open
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
267 std::ios_base::open_mode mode =
268 std::ios_base::out );
269 <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> );
271 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
272 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_sink_open">open
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
274 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
275 <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> );
277 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
278 <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> );
280 <SPAN CLASS=
"keyword">bool
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_sink_is_open">is_open
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
282 handle_type
<A CLASS=
"documented" HREF=
"#file_descriptor_sink_handle">handle
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
285 } }
<SPAN CLASS='comment'
>// End namespace boost::io
</SPAN></PRE>
287 <A NAME=
"file_descriptor_sink_ctor"></A>
288 <H4><CODE>file_descriptor_sink::file_descriptor_sink
</CODE></H4>
290 <PRE CLASS=
"broken_ie"> file_descriptor_sink();
291 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
292 file_descriptor_sink(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
293 std::ios_base::open_mode mode =
294 std::ios_base::out );
295 file_descriptor_sink(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
297 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
298 file_descriptor_sink( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
300 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
301 file_descriptor_sink(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
303 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
304 file_descriptor_sink( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
307 The first member constructs an empty
<CODE>file_descriptor_sink
</CODE>.
311 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>
315 The third member constructs a
<CODE>file_descriptor_sink
</CODE> to access the file with the given operating system or runtime-library file descriptor.
316 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the
<CODE>file_descriptor_sink
</CODE> being constructed
— or one of its copies
— is closed or destructed.
320 The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
321 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the
<CODE>file_descriptor_sink
</CODE> being constructed
— or one of its copies
— is closed or destructed.
325 The deprecated members are there to provide backwards compatability with old versions.
326 To use them you need to define
<CODE>BOOST_IOSTREAMS_USE_DEPRECATED
</CODE>.
327 The descriptor is always closed by
<CODE>close
</CODE> but only closed in destructors if
<CODE>close_on_exit
</CODE> is
<CODE>true
</CODE>.
330 <A NAME=
"file_descriptor_sink_open"></A>
331 <H4><CODE>file_descriptor_sink::open
</CODE></H4>
333 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
334 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
335 std::ios_base::open_mode mode =
336 std::ios_base::out );
337 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
339 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
340 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
342 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
343 <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> );
345 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
346 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
349 The parameters of
<CODE>open
</CODE> the same as those of the corresponding constructors.
350 If the file descriptor already holds a file, it'll be closed
351 (unless opened or constructed with
<CODE>never_close_handle
</CODE>).
354 <A NAME=
"file_descriptor_sink_is_open"></A>
355 <H4><CODE>file_descriptor_sink::is_open
</CODE></H4>
357 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">bool
</SPAN> is_open()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
359 <P>Returns
<CODE>true
</CODE> if the underlying file was opened successfully.
</P>
361 <A NAME=
"file_descriptor_sink_handle"></A>
362 <H4><CODE>file_descriptor_sink::handle
</CODE></H4>
364 <PRE CLASS=
"broken_ie"> handle_type handle()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
366 <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>
368 <A NAME=
"file_descriptor"></A>
369 <H3>Class
<CODE>file_descriptor
</CODE></H3>
373 <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.
377 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
379 <SPAN CLASS=
"keyword">enum
</SPAN> file_descriptor_flags {
384 <SPAN CLASS=
"keyword">class
</SPAN> file_descriptor {
385 <SPAN CLASS=
"keyword">public
</SPAN>:
386 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='keyword'
>char
</SPAN> char_type;
387 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> handle_type;
388 <SPAN CLASS='keyword'
>typedef
</SPAN> <SPAN CLASS='omitted'
>[implementation-defined]
</SPAN> category;
389 <A CLASS=
"documented" HREF=
"#file_descriptor_constructor">file_descriptor
</A>();
390 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
391 <A CLASS=
"documented" HREF=
"#file_descriptor_constructor">file_descriptor
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
392 std::ios_base::open_mode mode =
393 std::ios_base::in | std::ios_base::out );
394 <A CLASS=
"documented" HREF=
"#file_descriptor_constructor">file_descriptor
</A>(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
396 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
397 <A CLASS=
"documented" HREF=
"#file_descriptor_constructor">file_descriptor
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
399 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
400 <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> );
402 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
403 <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> );
405 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
406 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_open">open
</A>(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
407 std::ios_base::open_mode mode =
408 std::ios_base::in | std::ios_base::out );
409 <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> );
411 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
412 <SPAN CLASS=
"keyword">void
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_open">open
</A>( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
414 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
415 <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> );
417 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
418 <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> );
420 <SPAN CLASS=
"keyword">bool
</SPAN> <A CLASS=
"documented" HREF=
"#file_descriptor_is_open">is_open
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
422 handle_type
<A CLASS=
"documented" HREF=
"#file_descriptor_handle">handle
</A>()
<SPAN CLASS=
"keyword">const
</SPAN>;
425 } }
<SPAN CLASS='comment'
>// End namespace boost::io
</SPAN></PRE>
427 <A NAME=
"file_descriptor_constructor"></A>
428 <H4><CODE>file_descriptor::file_descriptor
</CODE></H4>
430 <PRE CLASS=
"broken_ie"> file_descriptor();
431 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
432 file_descriptor(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
433 std::ios_base::open_mode mode =
434 std::ios_base::in | std::ios_base::out );
435 file_descriptor(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
437 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
438 file_descriptor( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
440 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
441 file_descriptor(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
443 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
444 file_descriptor( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
447 The first member constructs an empty
<CODE>file_descriptor
</CODE>.
451 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>
455 The third member constructs a
<CODE>file_descriptor
</CODE> to access the file with the given operating system or runtime-library file descriptor.
456 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the
<CODE>file_descriptor
</CODE> being constructed
— or one of its copies
— is closed or destructed.
460 The fourth member is the same as the third, except that it accepts a Windows file handle instead of a file descriptor.
461 If the second argument is
<CODE>close_handle
</CODE>, the file descriptor is closed when the new
<CODE>file_descriptor
</CODE> — or one of its copies
— is closed or destructed.
465 The deprecated members are there to provide backwards compatability with old versions.
466 To use them you need to define
<CODE>BOOST_IOSTREAMS_USE_DEPRECATED
</CODE>.
467 The descriptor is always closed by
<CODE>close
</CODE> but only closed in destructors if
<CODE>close_on_exit
</CODE> is
<CODE>true
</CODE>.
470 <A NAME=
"file_descriptor_open"></A>
471 <H4><CODE>file_descriptor::open
</CODE></H4>
473 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Path
>
474 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">const
</SPAN> Path
& pathname,
475 std::ios_base::open_mode mode =
476 std::ios_base::in | std::ios_base::out );
477 <SPAN CLASS=
"keyword">void
</SPAN> open(
<SPAN CLASS=
"keyword">int
</SPAN> fd,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
479 <SPAN CLASS='comment'
>// Windows-only
</SPAN>
480 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">file_descriptor_flags
</SPAN> );
482 <SPAN CLASS='comment'
>// Deprecated
</SPAN>
483 <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> );
485 <SPAN CLASS='comment'
>// Deprecated, Windows-only
</SPAN>
486 <SPAN CLASS=
"keyword">void
</SPAN> open( HANDLE hFile,
<SPAN CLASS=
"keyword">bool
</SPAN> close_on_exit =
<SPAN CLASS=
"keyword">false
</SPAN> );
</PRE>
489 The parameters of
<CODE>open
</CODE> the same as those of the corresponding constructors.
490 If the file descriptor already holds a file, it'll be closed
491 (unless opened or constructed with
<CODE>never_close_handle
</CODE>).
494 <A NAME=
"file_descriptor_is_open"></A>
495 <H4><CODE>file_descriptor::is_open
</CODE></H4>
497 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">bool
</SPAN> is_open()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
499 <P>Returns
<CODE><SPAN CLASS=
"keyword">true
</SPAN></CODE> if the underlying file was opened successfully.
</P>
501 <A NAME=
"file_descriptor_handle"></A>
502 <H4><CODE>file_descriptor::handle
</CODE></H4>
504 <PRE CLASS=
"broken_ie"> handle_type handle()
<SPAN CLASS=
"keyword">const
</SPAN>;
</PRE>
506 <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>
508 <!-- Begin Footnotes -->
513 <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.
516 <!-- End Footnotes -->
518 <!-- Begin Footer -->
522 <P CLASS=
"copyright">© Copyright
2008 <a href=
"http://www.coderage.com/" target=
"_top">CodeRage, LLC
</a><br/>© Copyright
2004-
2007 <a href=
"http://www.coderage.com/turkanis/" target=
"_top">Jonathan Turkanis
</a></P>
523 <P CLASS=
"copyright">
524 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>)