aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/PipeFDs.h
blob: 20bd847c0772d2881d3b63ebfbe8bf400be31958 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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();

    /// 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();

    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();
};

}