From f7319b36f4f48cdf065b9a1472c9a848ca6f95bc Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 14:57:06 +0000 Subject: adapt self pipe --- src/pipe.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/pipe.cc (limited to 'src/pipe.cc') 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 +#include +#include + +#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 -- cgit v1.3.1-4-g156e