Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65431 - sandbox/SOC/2010/process/boost/process
From: boris_at_[hidden]
Date: 2010-09-15 15:48:58


Author: bschaeling
Date: 2010-09-15 15:48:58 EDT (Wed, 15 Sep 2010)
New Revision: 65431
URL: http://svn.boost.org/trac/boost/changeset/65431

Log:
Enhanced boost::process::handle to change the default behavior on close
Text files modified:
   sandbox/SOC/2010/process/boost/process/handle.hpp | 17 ++++++++++++-----
   sandbox/SOC/2010/process/boost/process/operations.hpp | 8 --------
   sandbox/SOC/2010/process/boost/process/stream_behavior.hpp | 17 +++--------------
   3 files changed, 15 insertions(+), 27 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/handle.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/handle.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/handle.hpp 2010-09-15 15:48:58 EDT (Wed, 15 Sep 2010)
@@ -71,6 +71,11 @@
     }
 
     /**
+ * RAII settings to specify if handle should be automatically closed.
+ */
+ enum close_type { do_close, dont_close };
+
+ /**
      * Constructs a handle from a native handle.
      *
      * This constructor creates a new \a handle object that takes
@@ -80,8 +85,8 @@
      *
      * \see release()
      */
- handle(native_type native)
- : impl_(boost::make_shared<impl>(native))
+ handle(native_type native, close_type close = handle::do_close)
+ : impl_(boost::make_shared<impl>(native, close))
     {
     }
 
@@ -139,14 +144,15 @@
     public:
         typedef handle::native_type native_type;
 
- impl(native_type native)
- : native_(native)
+ impl(native_type native, close_type close)
+ : native_(native),
+ close_(close)
         {
         }
 
         ~impl()
         {
- if (valid())
+ if (valid() && close_ == handle::do_close)
             {
 #if defined(BOOST_POSIX_API)
                 ::close(native_);
@@ -188,6 +194,7 @@
 
     private:
         native_type native_;
+ close_type close_;
     };
 
     /**

Modified: sandbox/SOC/2010/process/boost/process/operations.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/operations.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/operations.hpp 2010-09-15 15:48:58 EDT (Wed, 15 Sep 2010)
@@ -328,10 +328,6 @@
             delete[] envp.second[i];
         delete[] envp.second;
 
- stdin_pair.first.close();
- stdout_pair.first.close();
- stderr_pair.first.close();
-
         return child(pid,
             stdin_pair.second,
             stdout_pair.second,
@@ -367,10 +363,6 @@
         envstrs.get(), workdir.get(), &startup_info, &pi) == 0)
         BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("CreateProcess() failed");
 
- stdin_pair.first.close();
- stdout_pair.first.close();
- stderr_pair.first.close();
-
     handle hprocess(pi.hProcess);
 
     if (CloseHandle(pi.hThread) == 0)

Modified: sandbox/SOC/2010/process/boost/process/stream_behavior.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/stream_behavior.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/stream_behavior.hpp 2010-09-15 15:48:58 EDT (Wed, 15 Sep 2010)
@@ -63,28 +63,17 @@
 {
 public:
     inherit(handle::native_type h)
- : h_(h)
+ : h_(h, handle::dont_close)
     {
     }
 
     std::pair<handle, handle> operator()(bool) const
     {
-#if defined(BOOST_POSIX_API)
- int h = dup(h_);
- if (h == -1)
- BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("dup(2) failed");
-#elif defined(BOOST_WINDOWS_API)
- HANDLE h;
- if (!DuplicateHandle(GetCurrentProcess(), h_, GetCurrentProcess(),
- &h, 0, TRUE, DUPLICATE_SAME_ACCESS))
- BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
- "SetHandleInformation() failed");
-#endif
- return std::make_pair(h, handle());
+ return std::make_pair(h_, handle());
     }
 
 private:
- handle::native_type h_;
+ handle h_;
 };
 
 /**


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