diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 14:57:06 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 14:57:06 +0000 |
| commit | f7319b36f4f48cdf065b9a1472c9a848ca6f95bc (patch) | |
| tree | cedef12b3a1e803c605157cbbba6d2c8c826338d /src/pipe.cc | |
| parent | cd55aa462b112896240ab736bf60035fdb30ca2d (diff) | |
adapt self pipe
Diffstat (limited to 'src/pipe.cc')
| -rw-r--r-- | src/pipe.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pipe.cc b/src/pipe.cc new file mode 100644 index 0000000..5baaeae --- /dev/null +++ b/src/pipe.cc @@ -0,0 +1,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); +} + +}
\ No newline at end of file |
