8 #include <system_error>
14 notifier::notifier() {
16 std::string error_str = "failed to call pipe(), reason:";
17 error_str += strerror(errno);
18 throw std::system_error(std::error_code(errno, std::system_category()), error_str);
20 if (fcntl(m_pipe[1], F_SETFL, O_NONBLOCK)) {
21 std::string error_str = "failed to set piep's write side to nonblock mode, reason:";
22 error_str += strerror(errno);
23 throw std::system_error(std::error_code(errno, std::system_category()), error_str);
27 notifier::~notifier() {
32 void notifier::notify(const ntf_t & ntf) {
34 while (written < sizeof(ntf_t)) {
35 int n = write(m_pipe[1], (char *)&ntf, sizeof(ntf_t) - written);
45 bool notifier::wait(long timeout, std::vector<ntf_t> & ntfs) {
50 if(poll(&pfd, 1, timeout) == 1) {
51 int flags = fcntl(m_pipe[0], F_GETFL, 0);
53 fcntl(m_pipe[0], F_SETFL, flags);
57 while (readn < sizeof(ntf_t)) {
58 int n = read(m_pipe[0], &ntf, sizeof(ntf_t) - readn);
66 if (readn >= sizeof(ntf_t)) {
73 fcntl(m_pipe[0], F_SETFL, flags);