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 | |
18 | namespace Poco { |
19 | |
20 | |
21 | // |
22 | // PipeStreamBuf |
23 | // |
24 | |
25 | |
26 | PipeStreamBuf::PipeStreamBuf(const Pipe& pipe, openmode mode): |
27 | BufferedStreamBuf(STREAM_BUFFER_SIZE, mode), |
28 | _pipe(pipe) |
29 | { |
30 | } |
31 | |
32 | |
33 | PipeStreamBuf::~PipeStreamBuf() |
34 | { |
35 | } |
36 | |
37 | |
38 | int PipeStreamBuf::readFromDevice(char* buffer, std::streamsize length) |
39 | { |
40 | return _pipe.readBytes(buffer, (int) length); |
41 | } |
42 | |
43 | |
44 | int PipeStreamBuf::writeToDevice(const char* buffer, std::streamsize length) |
45 | { |
46 | return _pipe.writeBytes(buffer, (int) length); |
47 | } |
48 | |
49 | |
50 | void PipeStreamBuf::close() |
51 | { |
52 | _pipe.close(Pipe::CLOSE_BOTH); |
53 | } |
54 | |
55 | |
56 | // |
57 | // PipeIOS |
58 | // |
59 | |
60 | |
61 | PipeIOS::PipeIOS(const Pipe& pipe, openmode mode): |
62 | _buf(pipe, mode) |
63 | { |
64 | poco_ios_init(&_buf); |
65 | } |
66 | |
67 | |
68 | PipeIOS::~PipeIOS() |
69 | { |
70 | try |
71 | { |
72 | _buf.sync(); |
73 | } |
74 | catch (...) |
75 | { |
76 | } |
77 | } |
78 | |
79 | |
80 | PipeStreamBuf* PipeIOS::rdbuf() |
81 | { |
82 | return &_buf; |
83 | } |
84 | |
85 | |
86 | void PipeIOS::close() |
87 | { |
88 | _buf.sync(); |
89 | _buf.close(); |
90 | } |
91 | |
92 | |
93 | // |
94 | // PipeOutputStream |
95 | // |
96 | |
97 | |
98 | PipeOutputStream::PipeOutputStream(const Pipe& pipe): |
99 | PipeIOS(pipe, std::ios::out), |
100 | std::ostream(&_buf) |
101 | { |
102 | } |
103 | |
104 | |
105 | PipeOutputStream::~PipeOutputStream() |
106 | { |
107 | } |
108 | |
109 | |
110 | // |
111 | // PipeInputStream |
112 | // |
113 | |
114 | |
115 | PipeInputStream::PipeInputStream(const Pipe& pipe): |
116 | PipeIOS(pipe, std::ios::in), |
117 | std::istream(&_buf) |
118 | { |
119 | } |
120 | |
121 | |
122 | PipeInputStream::~PipeInputStream() |
123 | { |
124 | } |
125 | |
126 | |
127 | } // namespace Poco |
128 | |