aboutsummaryrefslogtreecommitdiff
path: root/src/pipe.cc
blob: 5baaeae0cbca85997b83590c6e2c1b2e07d813a4 (plain)
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

#include "pipe.h"

#include <unistd.h>
#include <cstdlib>
#include <fcntl.h>

#include "error.h"

namespace ov4
{

void self_pipe_init()
{
    int ret = pipe2(self_pipe_fd, O_NONBLOCK);
    if (ret != 0)
    {
        throw T_error(error_code::FAIL_TO_OPEN_PIPE, "Fail to open self pipe");
    }
}

/*
 * write a byte to self pipe
 * NB: you can ONLY determine that signal handler was called
 * but CANNOT determine the number of callings, or which signal was called
 * because when the pipe is full, nothing will be written
 */
int self_pipe_write()
{
    return write(self_pipe_fd[1], &SELF_PIPE_BYTE, 1);
}

}