2019-12-22 17:20:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
struct LazyPipeFDs
|
|
|
|
{
|
|
|
|
int fds_rw[2] = {-1, -1};
|
|
|
|
|
|
|
|
void open();
|
|
|
|
void close();
|
|
|
|
|
2020-11-27 10:12:11 +00:00
|
|
|
/// Set O_NONBLOCK to different ends of pipe preserving existing flags.
|
|
|
|
/// Throws an exception if fcntl was not successful.
|
|
|
|
void setNonBlockingWrite();
|
|
|
|
void setNonBlockingRead();
|
|
|
|
void setNonBlockingReadWrite();
|
|
|
|
|
2019-12-22 17:20:33 +00:00
|
|
|
void tryIncreaseSize(int desired_size);
|
|
|
|
|
|
|
|
~LazyPipeFDs();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Struct which opens new pipe on creation and closes it on destruction.
|
|
|
|
* Use `fds_rw` field to access pipe's file descriptors.
|
|
|
|
*/
|
|
|
|
struct PipeFDs : public LazyPipeFDs
|
|
|
|
{
|
|
|
|
PipeFDs();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|