|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63502 - in branches/release: boost/iostreams boost/iostreams/device libs/iostreams libs/iostreams/build libs/iostreams/doc libs/iostreams/doc/classes libs/iostreams/src libs/iostreams/test libs/iostreams/test/detail
From: daniel_james_at_[hidden]
Date: 2010-07-02 14:55:03
Author: danieljames
Date: 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
New Revision: 63502
URL: http://svn.boost.org/trac/boost/changeset/63502
Log:
Merge iostreams.
* New constructors/`open` for file descriptors.
Fixes #3517.
* Use `unique_path` instead of tmpnam. Refs #2325.
Added:
branches/release/libs/iostreams/test/deprecated_file_descriptor_test.cpp
- copied unchanged from r63501, /trunk/libs/iostreams/test/deprecated_file_descriptor_test.cpp
branches/release/libs/iostreams/test/detail/file_handle.hpp
- copied unchanged from r63501, /trunk/libs/iostreams/test/detail/file_handle.hpp
Properties modified:
branches/release/boost/iostreams/ (props changed)
branches/release/libs/iostreams/ (props changed)
Text files modified:
branches/release/boost/iostreams/device/file_descriptor.hpp | 54 ++++++++++++++
branches/release/libs/iostreams/build/Jamfile.v2 | 1
branches/release/libs/iostreams/doc/classes/file_descriptor.html | 152 +++++++++++++++++++++++++++++++++++----
branches/release/libs/iostreams/doc/release_notes.html | 19 ++++
branches/release/libs/iostreams/src/file_descriptor.cpp | 148 +++++++++++++++++++++++++++++++-------
branches/release/libs/iostreams/test/Jamfile.v2 | 25 ++++++
branches/release/libs/iostreams/test/detail/temp_file.hpp | 33 -------
branches/release/libs/iostreams/test/file_descriptor_test.cpp | 129 +++++++++++++++++++++++++++++++++
branches/release/libs/iostreams/test/tee_test.cpp | 37 ++++-----
9 files changed, 499 insertions(+), 99 deletions(-)
Modified: branches/release/boost/iostreams/device/file_descriptor.hpp
==============================================================================
--- branches/release/boost/iostreams/device/file_descriptor.hpp (original)
+++ branches/release/boost/iostreams/device/file_descriptor.hpp 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -37,6 +37,12 @@
class file_descriptor_sink;
namespace detail { struct file_descriptor_impl; }
+enum file_descriptor_flags
+{
+ never_close_handle = 0,
+ close_handle = 3
+};
+
class BOOST_IOSTREAMS_DECL file_descriptor {
public:
friend class file_descriptor_source;
@@ -52,10 +58,18 @@
file_descriptor();
// Constructors taking file desciptors
+ file_descriptor(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ file_descriptor(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+ // Constructors taking file desciptors
explicit file_descriptor(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor(int fd, bool close_on_exit = false);
#endif
+#endif
// Constructor taking a std:: string
explicit file_descriptor( const std::string& path,
@@ -81,10 +95,18 @@
file_descriptor(const file_descriptor& other);
// open overloads taking file descriptors
+ void open(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ void open(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+ // open overloads taking file descriptors
void open(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
void open(int fd, bool close_on_exit = false);
#endif
+#endif
// open overload taking a std::string
void open( const std::string& path,
@@ -144,10 +166,18 @@
file_descriptor_source() { }
// Constructors taking file desciptors
+ explicit file_descriptor_source(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ explicit file_descriptor_source(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+ // Constructors taking file desciptors
explicit file_descriptor_source(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor_source(int fd, bool close_on_exit = false);
#endif
+#endif
// Constructor taking a std:: string
explicit file_descriptor_source( const std::string& path,
@@ -166,11 +196,19 @@
// Copy constructor
file_descriptor_source(const file_descriptor_source& other);
+ // Constructors taking file desciptors
+ void open(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ void open(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
// open overloads taking file descriptors
void open(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
void open(int fd, bool close_on_exit = false);
#endif
+#endif
// open overload taking a std::string
void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
@@ -210,10 +248,18 @@
file_descriptor_sink() { }
// Constructors taking file desciptors
+ file_descriptor_sink(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ file_descriptor_sink(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+ // Constructors taking file desciptors
explicit file_descriptor_sink(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
explicit file_descriptor_sink(int fd, bool close_on_exit = false);
#endif
+#endif
// Constructor taking a std:: string
explicit file_descriptor_sink( const std::string& path,
@@ -233,10 +279,18 @@
file_descriptor_sink(const file_descriptor_sink& other);
// open overloads taking file descriptors
+ void open(handle_type fd, file_descriptor_flags);
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ void open(int fd, file_descriptor_flags);
+#endif
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+ // open overloads taking file descriptors
void open(handle_type fd, bool close_on_exit = false);
#ifdef BOOST_IOSTREAMS_WINDOWS
void open(int fd, bool close_on_exit = false);
#endif
+#endif
// open overload taking a std::string
void open( const std::string& path,
Modified: branches/release/libs/iostreams/build/Jamfile.v2
==============================================================================
--- branches/release/libs/iostreams/build/Jamfile.v2 (original)
+++ branches/release/libs/iostreams/build/Jamfile.v2 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -155,6 +155,7 @@
lib boost_iostreams
: $(sources)
: <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1
+ <define>BOOST_IOSTREAMS_USE_DEPRECATED
:
: <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1
;
Modified: branches/release/libs/iostreams/doc/classes/file_descriptor.html
==============================================================================
--- branches/release/libs/iostreams/doc/classes/file_descriptor.html (original)
+++ branches/release/libs/iostreams/doc/classes/file_descriptor.html 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -97,6 +97,11 @@
<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;
@@ -107,18 +112,30 @@
<A CLASS="documented" HREF="#file_descriptor_source_ctor">file_descriptor_source</A>( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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><<SPAN CLASS="keyword">typename</SPAN> Path>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_source_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</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">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>;
@@ -136,11 +153,16 @@
file_descriptor_source( <SPAN CLASS="keyword">const</SPAN> Path& 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> );
+ 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );</PRE>
+ 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>
@@ -150,11 +172,19 @@
</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>true</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed — or one of its copies — is closed.
+ 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 — or one of its copies — 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>true</CODE>, the file descriptor is closed when the <CODE>file_descriptor_source</CODE> being constructed — or one of its copies — is closed.
+ 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 — or one of its copies — 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>
@@ -164,13 +194,21 @@
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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>
@@ -198,6 +236,11 @@
<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;
@@ -213,13 +256,25 @@
<SPAN CLASS='comment'>// 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='comment'>// Deprecated</SPAN>
+ <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'>// Deprecated, 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="keyword">template</SPAN><<SPAN CLASS="keyword">typename</SPAN> Path>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_sink_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</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">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>;
@@ -240,7 +295,13 @@
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>
+ file_descriptor_sink( HANDLE hFile, <SPAN CLASS="keyword">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+
+ <SPAN CLASS='comment'>// Deprecated</SPAN>
+ file_descriptor_sink( <SPAN CLASS="keyword">int</SPAN> fd, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );
+
+ <SPAN CLASS='comment'>// Deprecated, Windows-only</SPAN>
+ file_descriptor_sink( HANDLE hFile, <SPAN CLASS="keyword">file_descriptor_flags</SPAN> );</PRE>
<P>
The first member constructs an empty <CODE>file_descriptor_sink</CODE>.
@@ -251,11 +312,19 @@
</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>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor_sink</CODE> — or one of its copies — is closed.
+ 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 — or one of its copies — 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 — or one of its copies — 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>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor_sink</CODE> — or one of its copies — is closed.
+ 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>
@@ -265,13 +334,21 @@
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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>
@@ -299,6 +376,11 @@
<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;
@@ -309,18 +391,30 @@
<A CLASS="documented" HREF="#file_descriptor_constructor">file_descriptor</A>( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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><<SPAN CLASS="keyword">typename</SPAN> Path>
<SPAN CLASS="keyword">void</SPAN> <A CLASS="documented" HREF="#file_descriptor_open">open</A>( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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>;
@@ -338,9 +432,15 @@
file_descriptor( <SPAN CLASS="keyword">const</SPAN> Path& 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> );
+ 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>
@@ -352,11 +452,19 @@
</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>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor</CODE> — or one of its copies — is closed.
+ 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 — or one of its copies — 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>true</CODE>, the file descriptor is closed when the new <CODE>file_descriptor</CODE> — or one of its copies — is closed.
+ 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> — or one of its copies — 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>
@@ -366,13 +474,21 @@
<SPAN CLASS="keyword">void</SPAN> open( <SPAN CLASS="keyword">const</SPAN> Path& 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">bool</SPAN> close_on_exit = <SPAN CLASS="keyword">false</SPAN> );
+ <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>
Modified: branches/release/libs/iostreams/doc/release_notes.html
==============================================================================
--- branches/release/libs/iostreams/doc/release_notes.html (original)
+++ branches/release/libs/iostreams/doc/release_notes.html 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -14,6 +14,23 @@
<!-- End Banner -->
+<h4>1.44</h4>
+
+<ul>
+ <li>
+ Lots of fixes, especially for compression and decompression, by Steven Watanabe.
+ </li>
+ <li>
+ New constructors and <code>open</code> methods from file descriptors/handles for
+ <code>file_descriptor</code>, <code>file_descriptor_source</code>
+ and <code>file_descriptor_sink</code>. See
+ <a title="File descriptor devices referece" href="classes/file_descriptor.html">the documentation</a>
+ for details. The old methods are still available is you define
+ <code>BOOST_IOSTREAMS_USE_DEPRECATED</code>
+ (#3517).
+ </li>
+</ul>
+
<h4>1.43</h4>
<p>
@@ -47,7 +64,7 @@
<h4>1.42</h4>
<p>
-Fixed many outstanding issues. Thanks to Richard Smith for mworking on a lot
+Fixed many outstanding issues. Thanks to Richard Smith for working on a lot
of these changes.
</p>
Modified: branches/release/libs/iostreams/src/file_descriptor.cpp
==============================================================================
--- branches/release/libs/iostreams/src/file_descriptor.cpp (original)
+++ branches/release/libs/iostreams/src/file_descriptor.cpp 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -48,22 +48,28 @@
// Contains the platform dependant implementation
struct file_descriptor_impl {
+ // Note: These need to match file_desciptor_flags
+ enum flags {
+ never_close = 0,
+ close_on_exit = 1,
+ close_on_close = 2,
+ close_always = 3
+ };
+
file_descriptor_impl();
~file_descriptor_impl();
- void open(file_handle fd, bool close_on_exit);
+ void open(file_handle fd, flags);
#ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, bool close_on_exit);
+ void open(int fd, flags);
#endif
void open(const detail::path&, BOOST_IOS::openmode);
bool is_open() const;
void close();
+ void close_impl(bool close_flag, bool throw_);
std::streamsize read(char* s, std::streamsize n);
std::streamsize write(const char* s, std::streamsize n);
std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
static file_handle invalid_handle();
- enum flags {
- close_on_exit = 1
- };
file_handle handle_;
int flags_;
};
@@ -76,30 +82,38 @@
file_descriptor_impl::~file_descriptor_impl()
{
- if (flags_ & close_on_exit) {
- try {
- close();
- } catch (...) { }
- }
+ close_impl(flags_ & close_on_exit, false);
}
-void file_descriptor_impl::open(file_handle fd, bool close_on_exit)
+void file_descriptor_impl::open(file_handle fd, flags f)
{
+ // Using 'close' to close the existing handle so that it will throw an
+ // exception if it fails.
+ //
+ // Only closing after assigning the new handle, so that the class will
+ // take ownership of the handle regardless of whether close throws.
+
+ file_descriptor_impl tmp;
+ tmp.handle_ = handle_;
+ tmp.flags_ = flags_ & close_on_exit ? close_on_close : never_close;
+
handle_ = fd;
- flags_ = close_on_exit ?
- file_descriptor_impl::close_on_exit :
- 0;
+ flags_ = f;
+
+ tmp.close();
}
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
-void file_descriptor_impl::open(int fd, bool close_on_exit)
-{ open(reinterpret_cast<file_handle>(_get_osfhandle(fd)), close_on_exit); }
+void file_descriptor_impl::open(int fd, flags f)
+{ open(reinterpret_cast<file_handle>(_get_osfhandle(fd)), f); }
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
void file_descriptor_impl::open(const detail::path& p, BOOST_IOS::openmode mode)
{
+ close_impl(flags_ & close_on_exit, true);
+
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
DWORD dwDesiredAccess;
DWORD dwCreationDisposition;
@@ -157,7 +171,7 @@
NULL ); // hTemplateFile
if (handle != INVALID_HANDLE_VALUE) {
handle_ = handle;
- flags_ |= close_on_exit;
+ flags_ = close_always;
} else {
flags_ = 0;
throw_system_failure("failed opening file");
@@ -214,7 +228,7 @@
boost::throw_exception(system_failure("failed opening file"));
} else {
handle_ = fd;
- flags_ = close_on_exit;
+ flags_ = close_always;
}
#endif // #ifndef BOOST_IOSTREAMS_WINDOWS //----------------------------------//
}
@@ -224,15 +238,21 @@
void file_descriptor_impl::close()
{
+ close_impl(flags_ & close_on_close, true);
+}
+
+void file_descriptor_impl::close_impl(bool close_flag, bool throw_) {
if (handle_ != invalid_handle()) {
- bool success =
- #ifdef BOOST_IOSTREAMS_WINDOWS
- ::CloseHandle(handle_) == 1;
- #else
- BOOST_IOSTREAMS_FD_CLOSE(handle_) != -1;
- #endif
- if (!success)
- throw_system_failure("failed closing file");
+ if (close_flag) {
+ bool success =
+ #ifdef BOOST_IOSTREAMS_WINDOWS
+ ::CloseHandle(handle_) == 1;
+ #else
+ BOOST_IOSTREAMS_FD_CLOSE(handle_) != -1;
+ #endif
+ if (!success && throw_)
+ throw_system_failure("failed closing file");
+ }
handle_ = invalid_handle();
flags_ = 0;
}
@@ -331,15 +351,27 @@
file_descriptor::file_descriptor() : pimpl_(new impl_type) { }
+file_descriptor::file_descriptor(handle_type fd, file_descriptor_flags f)
+ : pimpl_(new impl_type)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor::file_descriptor(handle_type fd, bool close_on_exit)
: pimpl_(new impl_type)
{ open(fd, close_on_exit); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+file_descriptor::file_descriptor(int fd, file_descriptor_flags f)
+ : pimpl_(new impl_type)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor::file_descriptor(int fd, bool close_on_exit)
: pimpl_(new impl_type)
{ open(fd, close_on_exit); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
@@ -357,13 +389,27 @@
: pimpl_(other.pimpl_)
{ }
+void file_descriptor::open(handle_type fd, file_descriptor_flags f)
+{ pimpl_->open(fd, static_cast<detail::file_descriptor_impl::flags>(f)); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor::open(handle_type fd, bool close_on_exit)
-{ pimpl_->open(fd, close_on_exit); }
+{ pimpl_->open(fd, close_on_exit ?
+ detail::file_descriptor_impl::close_always :
+ detail::file_descriptor_impl::close_on_close); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+void file_descriptor::open(int fd, file_descriptor_flags f)
+{ pimpl_->open(fd, static_cast<detail::file_descriptor_impl::flags>(f)); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor::open(int fd, bool close_on_exit)
-{ pimpl_->open(fd, close_on_exit); }
+{ pimpl_->open(fd, close_on_exit ?
+ detail::file_descriptor_impl::close_always :
+ detail::file_descriptor_impl::close_on_close); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
@@ -402,13 +448,24 @@
//------------------Implementation of file_descriptor_source------------------//
file_descriptor_source::file_descriptor_source(
+ handle_type fd, file_descriptor_flags f)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+file_descriptor_source::file_descriptor_source(
handle_type fd, bool close_on_exit)
{ open(fd, close_on_exit); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+file_descriptor_source::file_descriptor_source(int fd, file_descriptor_flags f)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_source::file_descriptor_source(int fd, bool close_on_exit)
{ open(fd, close_on_exit); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
@@ -425,13 +482,23 @@
: file_descriptor(static_cast<const file_descriptor&>(other))
{ }
+void file_descriptor_source::open(handle_type fd, file_descriptor_flags f)
+{ file_descriptor::open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor_source::open(handle_type fd, bool close_on_exit)
-{ file_descriptor::open(fd, close_on_exit); }
+{ file_descriptor::open(fd, close_on_exit); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+void file_descriptor_source::open(int fd, file_descriptor_flags f)
+{ file_descriptor::open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor_source::open(int fd, bool close_on_exit)
{ file_descriptor::open(fd, close_on_exit); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
@@ -454,13 +521,24 @@
//------------------Implementation of file_descriptor_sink--------------------//
file_descriptor_sink::file_descriptor_sink(
+ handle_type fd, file_descriptor_flags f)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
+file_descriptor_sink::file_descriptor_sink(
handle_type fd, bool close_on_exit)
{ open(fd, close_on_exit); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+file_descriptor_sink::file_descriptor_sink(int fd, file_descriptor_flags f)
+{ open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
file_descriptor_sink::file_descriptor_sink(int fd, bool close_on_exit)
{ open(fd, close_on_exit); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
@@ -476,13 +554,23 @@
: file_descriptor(static_cast<const file_descriptor&>(other))
{ }
+void file_descriptor_sink::open(handle_type fd, file_descriptor_flags f)
+{ file_descriptor::open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor_sink::open(handle_type fd, bool close_on_exit)
-{ file_descriptor::open(fd, close_on_exit); }
+{ file_descriptor::open(fd, close_on_exit); }
+#endif
#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+void file_descriptor_sink::open(int fd, file_descriptor_flags f)
+{ file_descriptor::open(fd, f); }
+
+#if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
void file_descriptor_sink::open(int fd, bool close_on_exit)
{ file_descriptor::open(fd, close_on_exit); }
+#endif
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
Modified: branches/release/libs/iostreams/test/Jamfile.v2
==============================================================================
--- branches/release/libs/iostreams/test/Jamfile.v2 (original)
+++ branches/release/libs/iostreams/test/Jamfile.v2 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -20,6 +20,7 @@
run
$(sources)
/boost/test//boost_unit_test_framework/<link>static
+ /boost/filesystem//boost_filesystem/<link>static
: # command
: # input files
: # build requirements
@@ -32,6 +33,24 @@
] ;
}
+rule compile-fail-iostreams ( sources * : requirements * : target-name ? ) {
+ return [
+ compile-fail
+ $(sources)
+ /boost/test//boost_unit_test_framework/<link>static
+ /boost/filesystem//boost_filesystem/<link>static
+ : # build requirements
+ <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
+ <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
+ <toolset>cw-9.3,<os>darwin:<runtime-link>static
+ <define>BOOST_IOSTREAMS_NO_LIB
+ <link>shared:<define>BOOST_IOSTREAMS_DYN_LINK=1
+ $(requirements)
+ : $(target-name)
+ ] ;
+}
+
+
local all-tests =
[ test-iostreams array_test.cpp ]
[ test-iostreams auto_close_test.cpp ]
@@ -51,6 +70,12 @@
[ test-iostreams file_test.cpp ]
[ test-iostreams file_descriptor_test.cpp
../build//boost_iostreams ]
+ [ test-iostreams deprecated_file_descriptor_test.cpp
+ ../build//boost_iostreams
+ : <define>BOOST_IOSTREAMS_USE_DEPRECATED ]
+ [ compile-fail-iostreams deprecated_file_descriptor_test.cpp
+ :
+ : deprecated_file_descriptor_fail ]
[ test-iostreams filtering_stream_test.cpp ]
[ test-iostreams finite_state_filter_test.cpp ]
[ test-iostreams flush_test.cpp ]
Modified: branches/release/libs/iostreams/test/detail/temp_file.hpp
==============================================================================
--- branches/release/libs/iostreams/test/detail/temp_file.hpp (original)
+++ branches/release/libs/iostreams/test/detail/temp_file.hpp 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -13,10 +13,7 @@
#include <cstdlib> // rand, toupper, tolower (VC6)
#include <fstream>
#include <string>
-#if defined(__CYGWIN__)
-# include <boost/random/linear_congruential.hpp>
-# include <boost/random/uniform_smallint.hpp>
-#endif
+#include <boost/filesystem/v3/operations.hpp>
#include "./constants.hpp"
#ifdef BOOST_NO_STDC_NAMESPACE
@@ -42,33 +39,9 @@
operator const ::std::string() const { return name_; }
private:
void set_name() {
- // Windows CreateFileMapping API function doesn't accept some
- // names generated by std::tmpnam.
- #if defined(_WIN32) || defined(__WIN32__) || \
- defined(WIN32) || defined(__CYGWIN__) \
- /**/
- for (int z = 0; z < 5; ++z)
- name_ += static_cast<char>('0' + rand());
- #else
- using namespace std;
- char tmp[L_tmpnam]; name_ = tmpnam(tmp);
- #endif
+ name_ = boost::filesystem3::unique_path().string();
}
- #if defined(__CYGWIN__)
- int rand()
- {
- static rand48 random_gen;
- static uniform_smallint<int> random_dist(0, 9);
- return random_dist(random_gen);
- }
- #else
- # if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
- int rand()
- {
- return (std::rand() * 10) / RAND_MAX;
- }
- # endif
- #endif
+
::std::string name_;
};
Modified: branches/release/libs/iostreams/test/file_descriptor_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/file_descriptor_test.cpp (original)
+++ branches/release/libs/iostreams/test/file_descriptor_test.cpp 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -6,16 +6,19 @@
// See http://www.boost.org/libs/iostreams for documentation.
#include <fstream>
+#include <fcntl.h>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include "detail/temp_file.hpp"
#include "detail/verification.hpp"
+#include "detail/file_handle.hpp"
using namespace boost;
using namespace boost::iostreams;
using namespace boost::iostreams::test;
+namespace boost_ios = boost::iostreams;
using std::ifstream;
using boost::unit_test::test_suite;
@@ -80,7 +83,7 @@
first->close();
BOOST_CHECK(!first->is_open());
}
-
+
// test illegal flag combinations
{
BOOST_CHECK_THROW(
@@ -507,9 +510,133 @@
}
}
+template <class FileDescriptor>
+void file_handle_test_impl(FileDescriptor*)
+{
+ test_file test1;
+ test_file test2;
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ {
+ FileDescriptor device1(handle, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ }
+ BOOST_CHECK_HANDLE_OPEN(handle);
+ close_file_handle(handle);
+ }
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ {
+ FileDescriptor device1(handle, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ }
+ BOOST_CHECK_HANDLE_CLOSED(handle);
+ }
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ FileDescriptor device1(handle, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ device1.close();
+ BOOST_CHECK(!device1.is_open());
+ BOOST_CHECK_HANDLE_OPEN(handle);
+ close_file_handle(handle);
+ }
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ FileDescriptor device1(handle, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ device1.close();
+ BOOST_CHECK(!device1.is_open());
+ BOOST_CHECK_HANDLE_CLOSED(handle);
+ }
+
+ {
+ boost_ios::detail::file_handle handle1 = open_file_handle(test1.name());
+ boost_ios::detail::file_handle handle2 = open_file_handle(test2.name());
+ {
+ FileDescriptor device1(handle1, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle1);
+ device1.open(handle2, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle2);
+ }
+ BOOST_CHECK_HANDLE_OPEN(handle1);
+ BOOST_CHECK_HANDLE_OPEN(handle2);
+ close_file_handle(handle1);
+ close_file_handle(handle2);
+ }
+
+ {
+ boost_ios::detail::file_handle handle1 = open_file_handle(test1.name());
+ boost_ios::detail::file_handle handle2 = open_file_handle(test2.name());
+ {
+ FileDescriptor device1(handle1, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle1);
+ device1.open(handle2, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle2);
+ BOOST_CHECK_HANDLE_CLOSED(handle1);
+ BOOST_CHECK_HANDLE_OPEN(handle2);
+ }
+ BOOST_CHECK_HANDLE_CLOSED(handle1);
+ BOOST_CHECK_HANDLE_CLOSED(handle2);
+ }
+
+ {
+ boost_ios::detail::file_handle handle1 = open_file_handle(test1.name());
+ boost_ios::detail::file_handle handle2 = open_file_handle(test2.name());
+ {
+ FileDescriptor device1(handle1, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle1);
+ device1.open(handle2, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle2);
+ BOOST_CHECK_HANDLE_CLOSED(handle1);
+ BOOST_CHECK_HANDLE_OPEN(handle2);
+ }
+ BOOST_CHECK_HANDLE_CLOSED(handle1);
+ BOOST_CHECK_HANDLE_OPEN(handle2);
+ close_file_handle(handle2);
+ }
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ {
+ FileDescriptor device1;
+ BOOST_CHECK(!device1.is_open());
+ device1.open(handle, boost_ios::never_close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ BOOST_CHECK_HANDLE_OPEN(handle);
+ }
+ BOOST_CHECK_HANDLE_OPEN(handle);
+ close_file_handle(handle);
+ }
+
+ {
+ boost_ios::detail::file_handle handle = open_file_handle(test1.name());
+ {
+ FileDescriptor device1;
+ BOOST_CHECK(!device1.is_open());
+ device1.open(handle, boost_ios::close_handle);
+ BOOST_CHECK(device1.handle() == handle);
+ BOOST_CHECK_HANDLE_OPEN(handle);
+ }
+ BOOST_CHECK_HANDLE_CLOSED(handle);
+ }
+}
+
+void file_handle_test()
+{
+ file_handle_test_impl((boost_ios::file_descriptor*) 0);
+ file_handle_test_impl((boost_ios::file_descriptor_source*) 0);
+ file_handle_test_impl((boost_ios::file_descriptor_sink*) 0);
+}
+
test_suite* init_unit_test_suite(int, char* [])
{
test_suite* test = BOOST_TEST_SUITE("file_descriptor test");
test->add(BOOST_TEST_CASE(&file_descriptor_test));
+ test->add(BOOST_TEST_CASE(&file_handle_test));
return test;
}
Modified: branches/release/libs/iostreams/test/tee_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/tee_test.cpp (original)
+++ branches/release/libs/iostreams/test/tee_test.cpp 2010-07-01 17:32:34 EDT (Thu, 01 Jul 2010)
@@ -22,7 +22,6 @@
using namespace boost::iostreams;
using namespace boost::iostreams::test;
using boost::unit_test::test_suite;
-namespace io = boost::iostreams;
void read_write_test()
{
@@ -154,7 +153,7 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
+ boost::iostreams::tee(
closable_device<output>(seq.new_operation(1)),
closable_device<
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
@@ -174,7 +173,7 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
+ boost::iostreams::tee(
closable_device<bidirectional>(
seq.new_operation(1),
seq.new_operation(2)
@@ -194,7 +193,7 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
+ boost::iostreams::tee(
closable_device<seekable>(seq.new_operation(1)),
closable_device<seekable>(seq.new_operation(2))
)
@@ -207,7 +206,7 @@
{
operation_sequence seq;
chain<output> ch;
- ch.push(io::tee(closable_device<output>(seq.new_operation(1))));
+ ch.push(boost::iostreams::tee(closable_device<output>(seq.new_operation(1))));
ch.push(closable_device<output>(seq.new_operation(2)));
BOOST_CHECK_NO_THROW(ch.reset());
BOOST_CHECK_OPERATION_SEQUENCE(seq);
@@ -218,7 +217,7 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
+ boost::iostreams::tee(
closable_device<bidirectional>(
seq.new_operation(1),
seq.new_operation(2)
@@ -234,7 +233,7 @@
{
operation_sequence seq;
chain<output> ch;
- ch.push(io::tee(closable_device<seekable>(seq.new_operation(1))));
+ ch.push(boost::iostreams::tee(closable_device<seekable>(seq.new_operation(1))));
ch.push(closable_device<seekable>(seq.new_operation(2)));
BOOST_CHECK_NO_THROW(ch.reset());
BOOST_CHECK_OPERATION_SEQUENCE(seq);
@@ -251,8 +250,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<output>(seq.new_operation(1)),
closable_device<output>(seq.new_operation(2))
),
@@ -268,8 +267,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<bidirectional>(
seq.new_operation(2),
seq.new_operation(3)
@@ -291,8 +290,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<seekable>(seq.new_operation(1)),
closable_device<seekable>(seq.new_operation(2))
),
@@ -309,8 +308,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<output>(seq.new_operation(1)),
closable_device<output>(seq.new_operation(2))
)
@@ -326,8 +325,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<bidirectional>(
seq.new_operation(2),
seq.new_operation(3)
@@ -349,8 +348,8 @@
operation_sequence seq;
chain<output> ch;
ch.push(
- io::tee(
- io::compose(
+ boost::iostreams::tee(
+ boost::iostreams::compose(
closable_filter<seekable>(seq.new_operation(1)),
closable_device<seekable>(seq.new_operation(2))
)
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk