comparison third_party/boost/process/postream.hpp @ 0:add35537fdbb tip

Initial import
author irh <ian.r.hobson@gmail.com>
date Thu, 25 Aug 2011 11:05:55 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:add35537fdbb
1 //
2 // Boost.Process
3 // ~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
6 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
7 // Copyright (c) 2009 Boris Schaeling
8 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
9 //
10 // Distributed under the Boost Software License, Version 1.0. (See accompanying
11 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 //
13
14 /**
15 * \file boost/process/postream.hpp
16 *
17 * Includes the declaration of the postream class.
18 */
19
20 #ifndef BOOST_PROCESS_POSTREAM_HPP
21 #define BOOST_PROCESS_POSTREAM_HPP
22
23 #include <boost/process/handle.hpp>
24 #include <boost/process/detail/systembuf.hpp>
25 #include <boost/noncopyable.hpp>
26 #include <ostream>
27
28 namespace boost {
29 namespace process {
30
31 /**
32 * Child process' input stream.
33 *
34 * The postream class represents an input communication channel with the
35 * child process. The child process reads data from this stream and the
36 * parent process can write to it through the postream object. In other
37 * words, from the child's point of view, the communication channel is an
38 * input one, but from the parent's point of view it is an output one;
39 * hence the confusing postream name.
40 *
41 * postream objects cannot be copied because they buffer data that flows
42 * through the communication channel.
43 *
44 * A postream object behaves as a std::ostream stream in all senses.
45 * The class is only provided because it must provide a method to let
46 * the caller explicitly close the communication channel.
47 *
48 * \remark Blocking remarks: Functions that write data to this
49 * stream can block if the associated handle blocks during
50 * the write. As this class is used to communicate with child
51 * processes through anonymous pipes, the most typical blocking
52 * condition happens when the child is not processing the data
53 * in the pipe's system buffer. When this happens, the buffer
54 * eventually fills up and the system blocks until the reader
55 * consumes some data, leaving some new room.
56 */
57 class postream : public std::ostream, public boost::noncopyable
58 {
59 public:
60 /**
61 * Creates a new process' input stream.
62 */
63 explicit postream(boost::process::handle h)
64 : std::ostream(0),
65 handle_(h),
66 systembuf_(handle_.native())
67 {
68 rdbuf(&systembuf_);
69 }
70
71 /**
72 * Returns the handle managed by this stream.
73 */
74 const boost::process::handle &handle() const
75 {
76 return handle_;
77 }
78
79 /**
80 * Returns the handle managed by this stream.
81 */
82 boost::process::handle &handle()
83 {
84 return handle_;
85 }
86
87 /**
88 * Closes the handle managed by this stream.
89 *
90 * Explicitly closes the handle managed by this stream. This
91 * function can be used by the user to tell the child process there
92 * is no more data to send.
93 */
94 void close()
95 {
96 systembuf_.sync();
97 handle_.close();
98 }
99
100 private:
101 /**
102 * The handle managed by this stream.
103 */
104 boost::process::handle handle_;
105
106 /**
107 * The systembuf object used to manage this stream's data.
108 */
109 detail::systembuf systembuf_;
110 };
111
112 }
113 }
114
115 #endif