|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r66296 - in sandbox/SOC/2010/process: boost/process boost/process/detail libs/process/test libs/process/test/util
From: boris_at_[hidden]
Date: 2010-10-31 12:37:56
Author: bschaeling
Date: 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
New Revision: 66296
URL: http://svn.boost.org/trac/boost/changeset/66296
Log:
Fixed two bugs and added test cases:
- boost::process::behavior::inherit sets flag HANDLE_FLAG_INHERIT (Windows only)
- boost::process::detail::basic_status_service's worker thread checks whether registered child exited (POSIX only)
Text files modified:
sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp | 16 +++++--------
sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp | 2
sandbox/SOC/2010/process/boost/process/stream_behavior.hpp | 5 ++++
sandbox/SOC/2010/process/libs/process/test/Jamfile.jam | 5 +++
sandbox/SOC/2010/process/libs/process/test/child.cpp | 36 ++++++++++++++++++++++++++++++
sandbox/SOC/2010/process/libs/process/test/util/boost.hpp | 2 +
sandbox/SOC/2010/process/libs/process/test/wait.cpp | 47 ++++++++++++++++++++++++++++++++++-----
7 files changed, 95 insertions(+), 18 deletions(-)
Modified: sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -221,18 +221,14 @@
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
"GetExitCodeProcess() failed");
boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
- bool regchild = false;
for (std::vector<implementation_type>::iterator it =
impls_.begin(); it != impls_.end(); ++it)
- regchild |= (*it)->complete(handle, exit_code);
- if (regchild)
- {
- std::vector<HANDLE>::iterator it = handles_.begin();
- std::advance(it, res - WAIT_OBJECT_0);
- handles_.erase(it);
- if (handles_.size() == 1)
- work_.reset();
- }
+ (*it)->complete(handle, exit_code);
+ std::vector<HANDLE>::iterator it = handles_.begin();
+ std::advance(it, res - WAIT_OBJECT_0);
+ handles_.erase(it);
+ if (handles_.size() == 1)
+ work_.reset();
}
}
#endif
Modified: sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -165,7 +165,7 @@
{
boost::iterator_range<operations_type::iterator> r =
ops_.equal_range(ph);
- if (r.begin() == r.end())
+ if (r.empty())
return false;
for (operations_type::iterator it = r.begin(); it != r.end(); ++it)
(*it->second)(exit_code);
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-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -66,6 +66,11 @@
inherit(handle::native_type h)
: h_(h, handle::dont_close)
{
+#if defined(BOOST_WINDOWS_API)
+ if (!SetHandleInformation(h_.native(), HANDLE_FLAG_INHERIT,
+ HANDLE_FLAG_INHERIT))
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("SetHandleInformation() failed");
+#endif
}
stream_ends operator()(stream_type) const
Modified: sandbox/SOC/2010/process/libs/process/test/Jamfile.jam
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/Jamfile.jam (original)
+++ sandbox/SOC/2010/process/libs/process/test/Jamfile.jam 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -17,6 +17,9 @@
alias bt : /boost//thread ;
explicit bt ;
+alias bio : /boost//iostreams ;
+explicit bio ;
+
project : requirements
<threading>multi
<target-os>windows:<define>WIN32_LEAN_AND_MEAN ;
@@ -39,7 +42,7 @@
run systembuf.cpp bfs ;
run arguments.cpp bfs : : helpers : <dependency>helpers ;
-run child.cpp bfs : : helpers : <dependency>helpers <target-os>windows:<library>rpcrt4 ;
+run child.cpp bfs bio : : helpers : <dependency>helpers <target-os>windows:<library>rpcrt4 ;
run executable.cpp bfs : : helpers : <dependency>helpers ;
run process.cpp bfs : : helpers : <dependency>helpers ;
run status.cpp bfs : : helpers : <dependency>helpers ;
Modified: sandbox/SOC/2010/process/libs/process/test/child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/child.cpp 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -30,6 +30,7 @@
#include <vector>
#include <utility>
#include <istream>
+#include <fstream>
#include <cstdlib>
BOOST_AUTO_TEST_CASE(test_close_stdin)
@@ -606,6 +607,41 @@
#endif
}
+BOOST_AUTO_TEST_CASE(test_inherit_file_descriptor)
+{
+ check_helpers();
+
+ std::vector<std::string> args;
+ args.push_back("echo-stdout");
+ args.push_back("message-stdout");
+
+ bio::file_descriptor_sink fd("6DB18578-DD0C-4ACB-AFD0-417F5CF2011D.txt");
+
+ bp::context ctx;
+ ctx.streams[bp::stdout_id] = bpb::inherit(fd.handle());
+
+ bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+
+ int s = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(s));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(s), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(s, EXIT_SUCCESS);
+#endif
+
+ fd.close();
+
+ std::string word;
+ std::ifstream is("6DB18578-DD0C-4ACB-AFD0-417F5CF2011D.txt");
+ is >> word;
+ is.close();
+
+ BOOST_CHECK_EQUAL(word, "message-stdout");
+
+ BOOST_REQUIRE(bfs::remove("6DB18578-DD0C-4ACB-AFD0-417F5CF2011D.txt"));
+}
+
#if defined(BOOST_POSIX_API)
BOOST_AUTO_TEST_CASE(test_posix)
{
Modified: sandbox/SOC/2010/process/libs/process/test/util/boost.hpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/util/boost.hpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/util/boost.hpp 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -20,6 +20,7 @@
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
+#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/lexical_cast.hpp>
@@ -34,6 +35,7 @@
namespace butf = boost::unit_test::framework;
namespace bfs = boost::filesystem;
namespace ba = boost::asio;
+namespace bio = boost::iostreams;
namespace bu = boost::uuids;
#endif
Modified: sandbox/SOC/2010/process/libs/process/test/wait.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/wait.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/wait.cpp 2010-10-31 12:37:50 EDT (Sun, 31 Oct 2010)
@@ -130,14 +130,20 @@
ioservice.run();
}
-void start_child()
+void start_child(const std::string &sec)
{
std::vector<std::string> args;
args.push_back("wait-exit");
- args.push_back("1");
+ args.push_back(sec);
bp::child c = bp::create_child(get_helpers_path(), args);
- c.wait();
+ int exit_code = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(exit_code));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(exit_code), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(exit_code, EXIT_SUCCESS);
+#endif
}
void handler2(boost::system::error_code ec, int exit_code, bool &called)
@@ -152,7 +158,7 @@
#endif
}
-BOOST_AUTO_TEST_CASE(test_status_sync_and_async_wait)
+BOOST_AUTO_TEST_CASE(test_sync_and_async_wait)
{
check_helpers();
@@ -166,13 +172,42 @@
args.push_back("2");
bp::child c = bp::create_child(get_helpers_path(), args);
- s.async_wait(c.get_id(), boost::bind(handler2, _1, _2, boost::ref(called)));
+ s.async_wait(c.get_id(), boost::bind(handler2, _1, _2,
+ boost::ref(called)));
- boost::thread(start_child);
+ boost::thread t(start_child, "1");
ioservice.run();
BOOST_CHECK_EQUAL(called, true);
+
+ t.join();
+}
+
+BOOST_AUTO_TEST_CASE(test_sync_and_async_wait2)
+{
+ check_helpers();
+
+ bool called = false;
+
+ ba::io_service ioservice;
+ bp::status s(ioservice);
+
+ std::vector<std::string> args;
+ args.push_back("wait-exit");
+ args.push_back("1");
+
+ bp::child c = bp::create_child(get_helpers_path(), args);
+ s.async_wait(c.get_id(), boost::bind(handler2, _1, _2,
+ boost::ref(called)));
+
+ boost::thread t(start_child, "2");
+
+ ioservice.run();
+
+ BOOST_CHECK_EQUAL(called, true);
+
+ t.join();
}
BOOST_AUTO_TEST_CASE(test_status_async_wait_shutdown)
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