Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62498 - sandbox/SOC/2010/process/libs/process/example
From: boris_at_[hidden]
Date: 2010-06-06 19:30:55


Author: bschaeling
Date: 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
New Revision: 62498
URL: http://svn.boost.org/trac/boost/changeset/62498

Log:
Updated sample programs
Text files modified:
   sandbox/SOC/2010/process/libs/process/example/child_stdin.cpp | 3 +--
   sandbox/SOC/2010/process/libs/process/example/child_stdout.cpp | 2 +-
   sandbox/SOC/2010/process/libs/process/example/read_async_from_child.cpp | 20 ++++++++++----------
   sandbox/SOC/2010/process/libs/process/example/read_async_from_parent.cpp | 25 ++++++++++++++++++++-----
   sandbox/SOC/2010/process/libs/process/example/wait_async_child.cpp | 27 ++++++---------------------
   sandbox/SOC/2010/process/libs/process/example/wait_async_process.cpp | 1 -
   sandbox/SOC/2010/process/libs/process/example/write_async_to_child.cpp | 5 +++--
   sandbox/SOC/2010/process/libs/process/example/write_async_to_parent.cpp | 5 +++--
   sandbox/SOC/2010/process/libs/process/example/write_to_child.cpp | 2 +-
   9 files changed, 45 insertions(+), 45 deletions(-)

Modified: sandbox/SOC/2010/process/libs/process/example/child_stdin.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/child_stdin.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/child_stdin.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -20,9 +20,8 @@
 {
     std::string exe = find_executable_in_path("ftp");
     context ctx;
- ctx.stdin_behavior = stream_behavior::capture;
+ ctx.stdin_behavior = capture;
     child c = create_child(exe, ctx);
     postream &os = c.get_stdin();
     os << "quit" << std::endl;
 }
-

Modified: sandbox/SOC/2010/process/libs/process/example/child_stdout.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/child_stdout.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/child_stdout.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -20,7 +20,7 @@
 {
     std::string exe = find_executable_in_path("hostname");
     context ctx;
- ctx.stdout_behavior = stream_behavior::capture;
+ ctx.stdout_behavior = capture;
     child c = create_child(exe, ctx);
     pistream &is = c.get_stdout();
     std::cout << is.rdbuf();

Modified: sandbox/SOC/2010/process/libs/process/example/read_async_from_child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/read_async_from_child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/read_async_from_child.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -21,33 +21,33 @@
 using namespace boost::asio;
 
 io_service ioservice;
-pistream *is;
 boost::array<char, 4096> buf;
 
-void begin_read();
-void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred);
+void begin_read(pipe &read_end);
+void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred, pipe &read_end);
 
 int main()
 {
     std::string exe = find_executable_in_path("hostname");
     context ctx;
- ctx.stdout_behavior = stream_behavior::capture;
+ ctx.stdout_behavior = capture;
     child c = create_child(exe, ctx);
- is = &c.get_stdout();
- begin_read();
+ pistream &is = c.get_stdout();
+ pipe read_end(ioservice, is.native());
+ begin_read(read_end);
     ioservice.run();
 }
 
-void begin_read()
+void begin_read(pipe &read_end)
 {
- is->async_read_some(buffer(buf), boost::bind(&end_read, placeholders::error, placeholders::bytes_transferred));
+ read_end.async_read_some(buffer(buf), boost::bind(&end_read, placeholders::error, placeholders::bytes_transferred, read_end));
 }
 
-void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred)
+void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred, pipe &read_end)
 {
     if (!ec)
     {
       std::cout << std::string(buf.data(), bytes_transferred) << std::flush;
- begin_read();
+ begin_read(read_end);
     }
 }

Modified: sandbox/SOC/2010/process/libs/process/example/read_async_from_parent.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/read_async_from_parent.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/read_async_from_parent.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -12,24 +12,39 @@
 
 #include <boost/all/process.hpp>
 #include <boost/asio.hpp>
+#include <boost/array.hpp>
 #include <boost/bind.hpp>
+#include <string>
+#include <iostream>
 
 using namespace boost::process;
 using namespace boost::asio;
 
 io_service ioservice;
+boost::array<char, 4096> buf;
 
-void end_write(const boost::system::error_code &ec);
+void begin_read(pipe &read_end);
+void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred, pipe &read_end);
 
 int main()
 {
- parent p(ioservice);
- std::string buffer;
+ parent p;
     pistream &is = p.get_stdout();
- async_read(os, &buffer, boost::bind(&end_read, placeholders::error));
+ pipe read_end(ioservice, is.native());
+ begin_read(read_end);
     ioservice.run();
 }
 
-void end_read(const boost::system::error_code &ec)
+void begin_read(pipe &read_end)
 {
+ read_end.async_read_some(buffer(buf), boost::bind(&end_read, placeholders::error, placeholders::bytes_transferred, read_end));
+}
+
+void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred, pipe &read_end)
+{
+ if (!ec)
+ {
+ std::cout << std::string(buf.data(), bytes_transferred) << std::flush;
+ begin_read(read_end);
+ }
 }

Modified: sandbox/SOC/2010/process/libs/process/example/wait_async_child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/wait_async_child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/wait_async_child.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -12,42 +12,27 @@
 
 #include <boost/all/process.hpp>
 #include <boost/asio.hpp>
-#include <boost/array.hpp>
 #include <boost/bind.hpp>
-#include <string>
 #include <iostream>
 
 using namespace boost::process;
 using namespace boost::asio;
 
 io_service ioservice;
-pistream *is;
-boost::array<char, 4096> buf;
 
-void begin_read();
-void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred);
+void end_wait(const boost::system::error_code &ec);
 
 int main()
 {
     std::string exe = find_executable_in_path("hostname");
- context ctx;
- ctx.io_service = &ioservice;
- child c = create_child(exe, ctx);
- is = &c.get_stdout();
- begin_read();
+ child c = create_child(exe);
+ status &s = p.status(ioservice);
+ s.async_wait(boost::bind(&end_wait, placeholders::error));
     ioservice.run();
 }
 
-void begin_read()
-{
- is->async_read_some(buffer(buf), boost::bind(&end_read, placeholders::error, placeholders::bytes_transferred));
-}
-
-void end_read(const boost::system::error_code &ec, std::size_t bytes_transferred)
+void end_wait(const boost::system::error_code &ec)
 {
     if (!ec)
- {
- std::cout << std::string(buf.data(), bytes_transferred) << std::flush;
- begin_read();
- }
+ std::cout << "process exited" << std::endl;
 }

Modified: sandbox/SOC/2010/process/libs/process/example/wait_async_process.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/wait_async_process.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/wait_async_process.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -21,7 +21,6 @@
 using namespace boost::asio;
 
 io_service ioservice;
-status s(ioservice);
 
 void end_wait(const boost::system::error_code &ec);
 

Modified: sandbox/SOC/2010/process/libs/process/example/write_async_to_child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/write_async_to_child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/write_async_to_child.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -27,10 +27,11 @@
 {
     std::string exe = find_executable_in_path("ftp");
     context ctx;
- ctx.stdin_behavior = stream_behavior::capture;
+ ctx.stdin_behavior = capture;
     child c = create_child(exe, ctx);
     postream &os = c.get_stdin();
- async_write(os, buffer("quit\n"), boost::bind(&end_write, placeholders::error));
+ pipe write_end(ioservice, os.native());
+ async_write(write_end, buffer("quit\n"), boost::bind(&end_write, placeholders::error));
     ioservice.run();
 }
 

Modified: sandbox/SOC/2010/process/libs/process/example/write_async_to_parent.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/write_async_to_parent.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/write_async_to_parent.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -23,9 +23,10 @@
 
 int main()
 {
- parent p(ioservice);
+ parent p;
     postream &os = p.get_stdin();
- async_write(os, buffer("Hello, world!"), boost::bind(&end_write, placeholders::error));
+ pipe write_end(ioservice, os.native());
+ async_write(write_end, buffer("Hello, world!"), boost::bind(&end_write, placeholders::error));
     ioservice.run();
 }
 

Modified: sandbox/SOC/2010/process/libs/process/example/write_to_child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/write_to_child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/write_to_child.cpp 2010-06-06 19:30:54 EDT (Sun, 06 Jun 2010)
@@ -20,7 +20,7 @@
 {
     std::string exe = find_executable_in_path("ftp");
     context ctx;
- ctx.stdin_behavior = stream_behavior::capture;
+ ctx.stdin_behavior = capture;
     child c = create_child(exe, ctx);
     postream &os = c.get_stdin();
     os << "quit" << std::endl;


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