1//
2// PipeStream.cpp
3//
4// Library: Foundation
5// Package: Processes
6// Module: PipeStream
7//
8// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/PipeStream.h"
16
17
18namespace Poco {
19
20
21//
22// PipeStreamBuf
23//
24
25
26PipeStreamBuf::PipeStreamBuf(const Pipe& pipe, openmode mode):
27 BufferedStreamBuf(STREAM_BUFFER_SIZE, mode),
28 _pipe(pipe)
29{
30}
31
32
33PipeStreamBuf::~PipeStreamBuf()
34{
35}
36
37
38int PipeStreamBuf::readFromDevice(char* buffer, std::streamsize length)
39{
40 return _pipe.readBytes(buffer, (int) length);
41}
42
43
44int PipeStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
45{
46 return _pipe.writeBytes(buffer, (int) length);
47}
48
49
50void PipeStreamBuf::close()
51{
52 _pipe.close(Pipe::CLOSE_BOTH);
53}
54
55
56//
57// PipeIOS
58//
59
60
61PipeIOS::PipeIOS(const Pipe& pipe, openmode mode):
62 _buf(pipe, mode)
63{
64 poco_ios_init(&_buf);
65}
66
67
68PipeIOS::~PipeIOS()
69{
70 try
71 {
72 _buf.sync();
73 }
74 catch (...)
75 {
76 }
77}
78
79
80PipeStreamBuf* PipeIOS::rdbuf()
81{
82 return &_buf;
83}
84
85
86void PipeIOS::close()
87{
88 _buf.sync();
89 _buf.close();
90}
91
92
93//
94// PipeOutputStream
95//
96
97
98PipeOutputStream::PipeOutputStream(const Pipe& pipe):
99 PipeIOS(pipe, std::ios::out),
100 std::ostream(&_buf)
101{
102}
103
104
105PipeOutputStream::~PipeOutputStream()
106{
107}
108
109
110//
111// PipeInputStream
112//
113
114
115PipeInputStream::PipeInputStream(const Pipe& pipe):
116 PipeIOS(pipe, std::ios::in),
117 std::istream(&_buf)
118{
119}
120
121
122PipeInputStream::~PipeInputStream()
123{
124}
125
126
127} // namespace Poco
128