Mercurial > hg > gpsynth
comparison third_party/boost/process/pistream.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/pistream.hpp | |
16 * | |
17 * Includes the declaration of the pistream class. | |
18 */ | |
19 | |
20 #ifndef BOOST_PROCESS_PISTREAM_HPP | |
21 #define BOOST_PROCESS_PISTREAM_HPP | |
22 | |
23 #include <boost/process/handle.hpp> | |
24 #include <boost/process/detail/systembuf.hpp> | |
25 #include <boost/noncopyable.hpp> | |
26 #include <istream> | |
27 | |
28 namespace boost { | |
29 namespace process { | |
30 | |
31 /** | |
32 * Child process' output stream. | |
33 * | |
34 * The pistream class represents an output communication channel with the | |
35 * child process. The child process writes data to this stream and the | |
36 * parent process can read it through the pistream object. In other | |
37 * words, from the child's point of view, the communication channel is an | |
38 * output one, but from the parent's point of view it is an input one; | |
39 * hence the confusing pistream name. | |
40 * | |
41 * pistream objects cannot be copied because they buffer data | |
42 * that flows through the communication channel. | |
43 * | |
44 * A pistream object behaves as a std::istream 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 read data from this | |
49 * stream can block if the associated handle blocks during | |
50 * the read. As this class is used to communicate with child | |
51 * processes through anonymous pipes, the most typical blocking | |
52 * condition happens when the child has no more data to send to | |
53 * the pipe's system buffer. When this happens, the buffer | |
54 * eventually empties and the system blocks until the writer | |
55 * generates some data. | |
56 */ | |
57 class pistream : public std::istream, public boost::noncopyable | |
58 { | |
59 public: | |
60 /** | |
61 * Creates a new process' output stream. | |
62 */ | |
63 explicit pistream(boost::process::handle h) | |
64 : std::istream(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 it's | |
92 * not willing to receive more data. | |
93 */ | |
94 void close() | |
95 { | |
96 handle_.close(); | |
97 } | |
98 | |
99 private: | |
100 /** | |
101 * The handle managed by this stream. | |
102 */ | |
103 boost::process::handle handle_; | |
104 | |
105 /** | |
106 * The systembuf object used to manage this stream's data. | |
107 */ | |
108 detail::systembuf systembuf_; | |
109 }; | |
110 | |
111 } | |
112 } | |
113 | |
114 #endif |