[Boost-bugs] [Boost C++ Libraries] #9597: "boost::iostreams::file_descriptor" doesn't close Windows low-level file descriptors properly when specifying "file_descriptor_flags::close_handle"

Subject: [Boost-bugs] [Boost C++ Libraries] #9597: "boost::iostreams::file_descriptor" doesn't close Windows low-level file descriptors properly when specifying "file_descriptor_flags::close_handle"
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-01-20 15:32:51


#9597: "boost::iostreams::file_descriptor" doesn't close Windows low-level file
descriptors properly when specifying "file_descriptor_flags::close_handle"
------------------------------+-----------------------
 Reporter: anonymous | Owner: turkanis
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: iostreams
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: file_descriptor |
------------------------------+-----------------------
 When opening a file on Windows using
 {{{boost::iostreams::file_descriptor}}},
 {{{boost::iostreams::file_descriptor_sink}}} or
 {{{boost::iostreams::file_descriptor_source}}} in combination with a low-
 level file descriptor and when specifying
 {{{file_descriptor_flags::close_handle}}}, then the file descriptor isn't
 closed properly on close/exit.

 Using one of the mentioned methods, the low-level file descriptor is
 converted to a Windows handle using the API call {{{_get_osfhandle}}}
 [#point1 (1)]:
 {{{#!c++
 void file_descriptor_impl::open(int fd, flags f)
 { open(reinterpret_cast<file_handle>(_get_osfhandle(fd)), f); }
 }}}
 When closing, the file handle is closed using {{{CloseHandle}}}:
 {{{#!c++
 void file_descriptor_impl::close_impl(bool close_flag, bool throw_) {
     if (handle_ != invalid_handle()) {
         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;
     }
 }
 }}}

 According to [#point1 (1)] the API call {{{_close}}} [#point2 (2)] shall
 be used to close a low-level file descriptor.
 Practical tests shew that every time a file is opened and closed using one
 of the mentioned methods, Windows (XP) assigns a new file descriptor with
 an increasing value to it, unless the program runs out of available file
 handles. Manually closing the file by specifying
 {{{file_descriptor_flags::close_handle}}} and calling {{{_close}}} solves
 this issue.

 [=#point1 (1)] http://msdn.microsoft.com/en-us/library/ks2530z6.aspx \\
 [=#point2 (2)] http://msdn.microsoft.com/en-us/library/5fzwd5ss.aspx

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9597>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC