Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65537 - in sandbox/SOC/2010/process: boost/process libs/process/example libs/process/test
From: boris_at_[hidden]
Date: 2010-09-22 16:42:22


Author: bschaeling
Date: 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
New Revision: 65537
URL: http://svn.boost.org/trac/boost/changeset/65537

Log:
Updated examples to make them compile again
Fixed a bug with stream_id definition
Text files modified:
   sandbox/SOC/2010/process/boost/process/stream_id.hpp | 4 +-
   sandbox/SOC/2010/process/libs/process/example/async_io.cpp | 6 ++--
   sandbox/SOC/2010/process/libs/process/example/create_child_context.cpp | 6 ++--
   sandbox/SOC/2010/process/libs/process/example/file_descriptors_setup.cpp | 47 +++++++++++----------------------------
   sandbox/SOC/2010/process/libs/process/example/redirect_to.cpp | 43 +++++++++++++++++-------------------
   sandbox/SOC/2010/process/libs/process/test/child.cpp | 9 +++----
   6 files changed, 45 insertions(+), 70 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/stream_id.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/stream_id.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/stream_id.hpp 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -39,9 +39,9 @@
  */
 typedef NativeStreamId stream_id;
 #elif defined(BOOST_POSIX_API)
-typedef std_stream_id stream_id;
-#elif defined(BOOST_WINDOWS_API)
 typedef int stream_id;
+#elif defined(BOOST_WINDOWS_API)
+typedef std_stream_id stream_id;
 #endif
 
 }

Modified: sandbox/SOC/2010/process/libs/process/example/async_io.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/async_io.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/async_io.cpp 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -30,10 +30,10 @@
     std::string exe = boost::process::find_executable_in_path("hostname");
     std::vector<std::string> args;
     boost::process::context ctx;
- ctx.stdout_behavior = boost::process::behavior::async_pipe();
+ ctx.streams[boost::process::stdout_id] =
+ boost::process::behavior::async_pipe();
     boost::process::child c = boost::process::create_child(exe, args, ctx);
- boost::process::pistream &is = c.get_stdout();
- boost::process::handle h = is.handle();
+ boost::process::handle h = c.get_handle(boost::process::stdout_id);
     boost::process::pipe read_end(ioservice, h.release());
     read_end.async_read_some(boost::asio::buffer(buf), handler);
     ioservice.run();

Modified: sandbox/SOC/2010/process/libs/process/example/create_child_context.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/create_child_context.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/create_child_context.cpp 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -36,7 +36,7 @@
     std::string exe = boost::process::find_executable_in_path("hostname");
     std::vector<std::string> args;
     boost::process::context ctx;
- ctx.stdout_behavior = boost::process::behavior::null();
+ ctx.streams[boost::process::stdout_id] = boost::process::behavior::null();
     boost::process::create_child(exe, args, ctx);
 //]
 }
@@ -47,9 +47,9 @@
     std::string exe = boost::process::find_executable_in_path("hostname");
     std::vector<std::string> args;
     boost::process::context ctx;
- ctx.stdout_behavior = boost::process::behavior::pipe();
+ ctx.streams[boost::process::stdout_id] = boost::process::behavior::pipe();
     boost::process::child c = boost::process::create_child(exe, args, ctx);
- boost::process::pistream &is = c.get_stdout();
+ boost::process::pistream is(c.get_handle(boost::process::stdout_id));
     std::cout << is.rdbuf() << std::flush;
 //]
 }

Modified: sandbox/SOC/2010/process/libs/process/example/file_descriptors_setup.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/file_descriptors_setup.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/file_descriptors_setup.cpp 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -18,49 +18,28 @@
 #include <boost/assign/list_of.hpp>
 #include <string>
 #include <vector>
-#include <utility>
 #include <iostream>
-#include <unistd.h>
-
-//[file_descriptors_context
-boost::process::stream_ends address = boost::process::behavior::pipe()(false);
-boost::process::stream_ends pid = boost::process::behavior::pipe()(false);
-
-class context : public boost::process::context
-{
-public:
- void setup(std::vector<bool> &closeflags)
- {
- if (dup2(address.child.native(), 3) == -1)
- {
- write(STDERR_FILENO, "dup2() failed\n", 14);
- _exit(127);
- }
- closeflags[3] = false;
-
- if (dup2(pid.child.native(), 4) == -1)
- {
- write(STDERR_FILENO, "dup2() failed\n", 14);
- _exit(127);
- }
- closeflags[4] = false;
- }
-};
-//]
 
 int main()
 {
 //[file_descriptors_main
     std::string exe = boost::process::find_executable_in_path("dbus-daemon");
+
     std::vector<std::string> args = boost::assign::list_of("--fork")
         ("--session")("--print-address=3")("--print-pid=4");
- context ctx;
- boost::process::create_child(exe, args, ctx);
- address.child.close();
- pid.child.close();
- boost::process::pistream isaddress(address.parent);
+
+ boost::process::context ctx;
+ ctx.streams[3] = boost::process::behavior::pipe(
+ boost::process::output_stream);
+ ctx.streams[4] = boost::process::behavior::pipe(
+ boost::process::output_stream);
+
+ boost::process::child c = boost::process::create_child(exe, args, ctx);
+
+ boost::process::pistream isaddress(c.get_handle(3));
     std::cout << isaddress.rdbuf() << std::endl;
- boost::process::pistream ispid(pid.parent);
+
+ boost::process::pistream ispid(c.get_handle(4));
     std::cout << ispid.rdbuf() << std::endl;
 //]
 }

Modified: sandbox/SOC/2010/process/libs/process/example/redirect_to.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/redirect_to.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/redirect_to.cpp 2010-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -12,30 +12,26 @@
 //
 
 #include <boost/process/all.hpp>
-
-#if defined(BOOST_POSIX_API)
-# include <unistd.h>
-#elif defined(BOOST_WINDOWS_API)
-# include <windows.h>
-#else
-# error "Unsupported platform."
-#endif
-
 #include <boost/bind.hpp>
 #include <iostream>
-#include <utility>
-#include <stdexcept>
 
 //[redirect_to_stream
-boost::process::stream_ends redirect_to(boost::process::handle h)
+class redirect_to
 {
-#if defined(BOOST_WINDOWS_API)
- if (!SetHandleInformation(h.native(), HANDLE_FLAG_INHERIT,
- HANDLE_FLAG_INHERIT))
- throw std::runtime_error("DuplicateHandle() failed");
-#endif
- return boost::process::stream_ends(h, boost::process::handle());
-}
+public:
+ redirect_to(boost::process::handle h)
+ : h_(h)
+ {
+ }
+
+ boost::process::stream_ends operator()(boost::process::stream_type) const
+ {
+ return boost::process::stream_ends(h_, boost::process::handle());
+ }
+
+private:
+ boost::process::handle h_;
+};
 //]
 
 //[redirect_to_main
@@ -51,16 +47,17 @@
 
     std::vector<std::string> args;
 
- boost::process::stream_ends ends = boost::process::behavior::pipe()(false);
+ boost::process::stream_ends ends = boost::process::behavior::pipe()
+ (boost::process::output_stream);
 
     boost::process::context ctx;
- ctx.stdout_behavior = boost::bind(forward, ends);
- ctx.stderr_behavior = boost::bind(redirect_to, ends.child);
+ ctx.streams[boost::process::stdout_id] = boost::bind(forward, ends);
+ ctx.streams[boost::process::stderr_id] = redirect_to(ends.child);
 
     boost::process::child c = boost::process::create_child(
         executable, args, ctx);
 
- boost::process::pistream &is = c.get_stdout();
+ boost::process::pistream is(c.get_handle(boost::process::stdout_id));
     std::cout << is.rdbuf() << std::flush;
 }
 //]

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-09-22 16:42:20 EDT (Wed, 22 Sep 2010)
@@ -610,12 +610,12 @@
     args.push_back("test");
 
     bp::context ctx;
- ctx.streams[static_cast<bp::stream_id>(10)] = bpb::pipe(bp::output_stream);
+ ctx.streams[10] = bpb::pipe(bp::output_stream);
 
     bp::child c = bp::create_child(get_helpers_path(), args, ctx);
 
     std::string word;
- bp::pistream is(c.get_handle(static_cast<bp::stream_id>(10)));
+ bp::pistream is(c.get_handle(10));
     is >> word;
     BOOST_CHECK_EQUAL(word, "test");
 
@@ -663,8 +663,7 @@
     args.push_back("test");
 
     bp::context ctx;
- ctx.streams[static_cast<bp::std_stream_id>(3)] =
- bpb::pipe(bp::output_stream);
+ ctx.streams[3] = bpb::pipe(bp::output_stream);
 
     // File descriptors must be closed after context is instantiated as the
     // context constructor uses the behavior inherit which tries to dup()
@@ -682,7 +681,7 @@
 
     bp::child c = bp::create_child(get_helpers_path(), args, ctx);
 
- int res = dup2(c.get_handle(static_cast<bp::std_stream_id>(3)).native(), 0);
+ int res = dup2(c.get_handle(3).native(), 0);
     std::string word;
     if (res != -1)
         std::cin >> word;


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