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