2019-02-09 21:40:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-07-05 13:48:47 +00:00
|
|
|
#include <unistd.h>
|
2019-02-09 21:40:10 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
/**
|
|
|
|
* Struct containing a pipe with lazy initialization.
|
|
|
|
* Use `open` and `close` methods to manipulate pipe and `fds_rw` field to access
|
|
|
|
* pipe's file descriptors.
|
|
|
|
*/
|
2019-02-09 21:40:10 +00:00
|
|
|
struct LazyPipe
|
|
|
|
{
|
|
|
|
int fds_rw[2] = {-1, -1};
|
|
|
|
|
|
|
|
LazyPipe() = default;
|
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
void open();
|
|
|
|
|
|
|
|
void close();
|
2019-02-09 21:40:10 +00:00
|
|
|
|
2019-05-19 20:22:44 +00:00
|
|
|
virtual ~LazyPipe() = default;
|
2019-02-09 21:40:10 +00:00
|
|
|
};
|
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
/**
|
|
|
|
* Struct which opens new pipe on creation and closes it on destruction.
|
|
|
|
* Use `fds_rw` field to access pipe's file descriptors.
|
|
|
|
*/
|
|
|
|
struct Pipe : public LazyPipe
|
|
|
|
{
|
|
|
|
Pipe();
|
2019-05-19 20:22:44 +00:00
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
~Pipe();
|
2019-02-09 21:40:10 +00:00
|
|
|
};
|