summaryrefslogtreecommitdiff
path: root/boost/process/pipe.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/process/pipe.hpp')
-rw-r--r--boost/process/pipe.hpp124
1 files changed, 123 insertions, 1 deletions
diff --git a/boost/process/pipe.hpp b/boost/process/pipe.hpp
index dd4af09d63..2040c78e3d 100644
--- a/boost/process/pipe.hpp
+++ b/boost/process/pipe.hpp
@@ -120,6 +120,13 @@ struct basic_pipebuf : std::basic_streambuf<CharT, Traits>
///Move Constructor
basic_pipebuf(basic_pipebuf && ) = default;
+ ///Destructor -> writes the frest of the data
+ ~basic_pipebuf()
+ {
+ if (is_open())
+ overflow(Traits::eof());
+ }
+
///Move construct from a pipe.
basic_pipebuf(pipe_type && p) : _pipe(std::move(p)),
_write(default_buffer_size),
@@ -155,7 +162,7 @@ struct basic_pipebuf : std::basic_streambuf<CharT, Traits>
///Writes characters to the associated output sequence from the put area
int_type overflow(int_type ch = traits_type::eof()) override
{
- if ((ch != traits_type::eof()) && _pipe.is_open())
+ if (_pipe.is_open() && (ch != traits_type::eof()))
{
if (this->pptr() == this->epptr())
{
@@ -173,6 +180,9 @@ struct basic_pipebuf : std::basic_streambuf<CharT, Traits>
return ch;
}
}
+ else if (ch == traits_type::eof())
+ this->sync();
+
return traits_type::eof();
}
///Synchronizes the buffers with the associated character sequence
@@ -212,6 +222,36 @@ struct basic_pipebuf : std::basic_streambuf<CharT, Traits>
const pipe_type &pipe() const & {return _pipe;}
///Get a rvalue reference to the pipe. Qualified as rvalue.
pipe_type && pipe() && {return std::move(_pipe);}
+
+ ///Check if the pipe is open
+ bool is_open() const {return _pipe.is_open(); }
+
+ ///Open a new pipe
+ basic_pipebuf<CharT, Traits>* open()
+ {
+ if (is_open())
+ return nullptr;
+ _pipe = pipe();
+ return this;
+ }
+
+ ///Open a new named pipe
+ basic_pipebuf<CharT, Traits>* open(const std::string & name)
+ {
+ if (is_open())
+ return nullptr;
+ _pipe = pipe(name);
+ return this;
+ }
+
+ ///Flush the buffer & close the pipe
+ basic_pipebuf<CharT, Traits>* close()
+ {
+ if (!is_open())
+ return nullptr;
+ overflow(Traits::eof());
+ return this;
+ }
private:
pipe_type _pipe;
std::vector<char_type> _write;
@@ -223,8 +263,13 @@ private:
return false;
auto base = this->pbase();
+
+ if (base == this->pptr())
+ return true;
+
std::ptrdiff_t wrt = _pipe.write(base,
static_cast<typename pipe_type::int_type>(this->pptr() - base));
+
std::ptrdiff_t diff = this->pptr() - base;
if (wrt < diff)
@@ -320,6 +365,33 @@ public:
const pipe_type &pipe() const & {return _buf.pipe();}
///Get a rvalue reference to the pipe. Qualified as rvalue.
pipe_type && pipe() && {return std::move(_buf).pipe();}
+ ///Check if the pipe is open
+ bool is_open() const {return _buf->is_open();}
+
+ ///Open a new pipe
+ void open()
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Open a new named pipe
+ void open(const std::string & name)
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Flush the buffer & close the pipe
+ void close()
+ {
+ if (_buf.close() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ }
};
typedef basic_ipstream<char> ipstream;
@@ -402,6 +474,31 @@ public:
const pipe_type &pipe() const & {return _buf.pipe();}
///Get a rvalue reference to the pipe. Qualified as rvalue.
pipe_type && pipe() && {return std::move(_buf).pipe();}
+
+ ///Open a new pipe
+ void open()
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Open a new named pipe
+ void open(const std::string & name)
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Flush the buffer & close the pipe
+ void close()
+ {
+ if (_buf.close() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ }
};
typedef basic_opstream<char> opstream;
@@ -484,6 +581,31 @@ public:
const pipe_type &pipe() const & {return _buf.pipe();}
///Get a rvalue reference to the pipe. Qualified as rvalue.
pipe_type && pipe() && {return std::move(_buf).pipe();}
+
+ ///Open a new pipe
+ void open()
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Open a new named pipe
+ void open(const std::string & name)
+ {
+ if (_buf.open() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ else
+ this->clear();
+ }
+
+ ///Flush the buffer & close the pipe
+ void close()
+ {
+ if (_buf.close() == nullptr)
+ this->setstate(std::ios_base::failbit);
+ }
};
typedef basic_pstream<char> pstream;