bool registerTimer(DataObject<TimerObject>& dot) { int fd = dot.get([](const TimerObject& t){ return t._fd; }); #ifdef __linux__ epoll_event evt {}; evt.events = EPOLLIN; evt.data.fd = fd; { std::lock_guard<std::mutex> lock(_mtx); _notify.insert({ fd, dot }); } if (::epoll_ctl(_epfd, EPOLL_CTL_ADD, fd, &evt) < 0) { // Delete it again in the case of error { std::lock_guard<std::mutex> lock(_mtx); _notify.erase(fd); } Logger::pLOG->error("Epoll control error at TimerObjectReactor.registerTimer: {}", std::strerror(errno)); return false; } #endif return true; }
bool unregisterTimer(DataObject<TimerObject>& dot) { bool ret = true; int fd = dot.get([](const TimerObject& t){ return t._fd; }); #ifdef __linux__ if (::epoll_ctl(_epfd, EPOLL_CTL_DEL, fd, 0) < 0) { Logger::pLOG->error("Epoll control error at TimerObjectReactor.unregisterTimer: {}", std::strerror(errno)); ret = false; } // Erase it in any case { std::lock_guard<std::mutex> lock(_mtx); _notify.erase(fd); } #endif return ret; }