Boost C++ Libraries: Ticket #3517: [iostreams] stream<file_descriptor_source> closes supplied descriptor https://svn.boost.org/trac10/ticket/3517 <p> The instance of stream &lt;file_descriptor_source&gt; closes supplied file descriptor on destruction even if the second specified argument is 'false'. </p> <p> Expected behavior: descriptor remains opened after stream destruction </p> <p> The repro application source is at <a class="ext-link" href="http://alexanderchuranov.com/boost-iostreams-autoclose-bug.cc"><span class="icon">​</span>http://alexanderchuranov.com/boost-iostreams-autoclose-bug.cc</a> . </p> <p> Workaround: call "set_auto_close(false)" right after stream construction. </p> <p> It is believed that the root cause of the issue is indirect_stream having default constructor always initializing it's "flags_" member to f_auto_close. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3517 Trac 1.4.3 Steven Watanabe Tue, 15 Jun 2010 03:20:03 GMT <link>https://svn.boost.org/trac10/ticket/3517#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3517#comment:1</guid> <description> <p> I think the correct fix is to make close() for file_descriptor a no-op, when you pass in an external file descriptor. This makes file_descriptor's semantics simpler, as it either owns the underlying file descriptor or it doesn't. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Tue, 15 Jun 2010 08:10:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3517#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3517#comment:2</guid> <description> <p> I think you're right, but I feel cautious about silently changing existing behaviour. I also dislike the boolean parameter. So I'd create a new constructor which takes flags to indicated if the handle should be closed. And maybe <code>close_on_exit</code> if someone wants it. I'd deprecate the existing constructor, so that it's only present if a macro is defined. That way we'd break the compile rather than subtly changing the code. What do you think of something like this? Am I being over-cautious? </p> <pre class="wiki">namespace boost { namespace iostreams { enum file_handle_flags { close_handle, // maybe owns_handle? never_close_handle, close_handle_on_exit // Probably shouldn't be public. }; class file_descriptor { public: typedef char char_type; typedef [implementation-defined] category; file_descriptor( const std::string&amp; pathname, std::ios_base::open_mode mode = std::ios_base::in | std::ios_base::out ); file_descriptor( int fd, file_handle_flags); // Windows-only file_descriptor( HANDLE hFile, file_handle_flags); // Maybe something with a version number... #if defined(BOOST_IOSTREAMS_USE_DEPRECATED) file_descriptor( int fd, bool close_on_exit = false ); // Windows-only file_descriptor( HANDLE hFile, bool close_on_exit = false ); #endif bool is_open() const; }; } } // End namespace boost::io </pre><p> It'll be more verbose but I think it's worth it to clear up the ambiguity. Oh, and those constructors should probably have been <code>explicit</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Tue, 15 Jun 2010 13:54:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3517#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3517#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3517#comment:2" title="Comment 2">danieljames</a>: </p> <blockquote class="citation"> <p> I think you're right, but I feel cautious about silently changing existing behaviour. I also dislike the boolean parameter. So I'd create a new constructor which takes flags to indicated if the handle should be closed. And maybe <code>close_on_exit</code> if someone wants it. I'd deprecate the existing constructor, so that it's only present if a macro is defined. That way we'd break the compile rather than subtly changing the code. What do you think of something like this? </p> </blockquote> <p> Sounds good to me. </p> <blockquote class="citation"> <p> Am I being over-cautious? </p> </blockquote> <p> I don't think so. </p> <blockquote class="citation"> <p> &lt;snip code&gt; </p> <p> It'll be more verbose but I think it's worth it to clear up the ambiguity. Oh, and those constructors should probably have been <code>explicit</code>. </p> </blockquote> <p> Yep. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Tue, 15 Jun 2010 20:22:33 GMT</pubDate> <title>owner, status, milestone changed https://svn.boost.org/trac10/ticket/3517#comment:4 https://svn.boost.org/trac10/ticket/3517#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Jonathan Turkanis</span> to <span class="trac-author">Daniel James</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.41.0</span> → <span class="trac-field-new">Boost 1.44.0</span> </li> </ul> Ticket Daniel James Tue, 29 Jun 2010 14:15:17 GMT <link>https://svn.boost.org/trac10/ticket/3517#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3517#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/63430" title="Try to improve file_descriptor's ownership policies. Refs #3517 * ...">[63430]</a>) Try to improve file_descriptor's ownership policies. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3517" title="#3517: Bugs: [iostreams] stream&lt;file_descriptor_source&gt; closes supplied descriptor (closed: fixed)">#3517</a> </p> <ul><li>Deprecate the old 'close_on_exit' constructors. </li><li>Introduce new constructors from file handle, taking either <code>never_close_handle</code> or <code>close_handle</code>. </li><li>Close current file handle when opening a new file handle, if it would have been closed in the destructor. </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Thu, 01 Jul 2010 21:32:36 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3517#comment:6 https://svn.boost.org/trac10/ticket/3517#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/63502" title="Merge iostreams. * New constructors/`open` for file descriptors. ...">[63502]</a>) Merge iostreams. </p> <ul><li>New constructors/<code>open</code> for file descriptors. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3517" title="#3517: Bugs: [iostreams] stream&lt;file_descriptor_source&gt; closes supplied descriptor (closed: fixed)">#3517</a>. </li><li>Use <code>unique_path</code> instead of tmpnam. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2325" title="#2325: Bugs: Use of tmpnam may produce spurious test results (closed: fixed)">#2325</a>. </li></ul> Ticket Daniel James Tue, 06 Jul 2010 00:55:18 GMT <link>https://svn.boost.org/trac10/ticket/3517#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3517#comment:7</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/63679" title="Partially merge iostreams. * New constructors/`open` for file ...">[63679]</a>) Partially merge iostreams. </p> <ul><li>New constructors/<code>open</code> for file descriptors. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3517" title="#3517: Bugs: [iostreams] stream&lt;file_descriptor_source&gt; closes supplied descriptor (closed: fixed)">#3517</a>. </li><li>Leaving out changes which depend on filesystem v3. </li></ul> </description> <category>Ticket</category> </item> </channel> </rss>