MatN work for versatile appimage creation for all types of os
[goodguy/cinelerra.git] / cinelerra-5.1 / tools / makeappimagetool / includes / pipe_reader.h
1 #pragma once
2
3 #include <string>
4 #include <set>
5 #include <vector>
6 #include <poll.h>
7
8 /**
9  * Reads from a pipe when data is available, and hands data to registered callbacks.
10  */
11 class pipe_reader {
12 private:
13     const int pipe_fd_;
14
15 public:
16     /**
17      * Construct new instance from pipe file descriptor.
18      * @param pipe_fd file descriptor for pipe we will read from (e.g., a subprocess's stdout, stderr pipes)
19      */
20     explicit pipe_reader(int pipe_fd);
21
22     /**
23      * Read from pipe file descriptor and store data in buffer.
24      * This method is non-blocking, i.e., if there is no data to read, it returns immediately.
25      * Otherwise, it will read until either of the following conditions is met:
26      *
27      *     - no more data left in the pipe to be read
28      *     - buffer is completely filled
29      *
30      * On errors, a subprocess_error is thrown.
31      *
32      * @param buffer buffer to store read data into
33      * @returns amount of characters read from the pipe
34      */
35     size_t read(std::vector<std::string::value_type>& buffer) const;
36 };