Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DobbyStream.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2016 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: DobbyStream.h
21  *
22  */
23 #ifndef DOBBYSTREAM_H
24 #define DOBBYSTREAM_H
25 
26 #include <sys/types.h>
27 
28 #include <string>
29 #include <thread>
30 #include <vector>
31 
32 // -----------------------------------------------------------------------------
41 {
42 public:
43  virtual ~IDobbyStream() = default;
44 
45 public:
46  virtual int dupWriteFD(int newFd = -1, bool closeExec = true) const = 0;
47 };
48 
49 
50 // -----------------------------------------------------------------------------
59 {
60 public:
61  ~DobbyDevNullStream() final = default;
62 
63 public:
64  int dupWriteFD(int newFd, bool closeExec) const override;
65 };
66 
67 
68 // -----------------------------------------------------------------------------
81 {
82 public:
83  explicit DobbyBufferStream(ssize_t limit = -1);
84  ~DobbyBufferStream() final;
85 
86 public:
87  int dupWriteFD(int newFd, bool closeExec) const override;
88 
89 public:
90  std::vector<char> getBuffer() const;
91  int getMemFd() const;
92 
93 private:
94  int mMemFd;
95 };
96 
97 #endif // !defined(DOBBYSTREAM_H)
Stream that just redirects all the input to an internal memory buffer.
Definition: DobbyStream.h:81
DobbyBufferStream(ssize_t limit=-1)
Constructs the buffer using an memfd.
Definition: DobbyStream.cpp:129
int dupWriteFD(int newFd, bool closeExec) const override
Returns a dup'd file descriptor for the write side of the stream.
Definition: DobbyStream.cpp:174
std::vector< char > getBuffer() const
Reads all the data in the buffer.
Definition: DobbyStream.cpp:222
Stream that just redirects all the input to /dev/null.
Definition: DobbyStream.h:59
int dupWriteFD(int newFd, bool closeExec) const override
Returns a dup'd file descriptor for the write side of the stream.
Definition: DobbyStream.cpp:86
Interface for all character streams used in the daemon.
Definition: DobbyStream.h:41