#include #include #include "log.h" #include "misc.h" #include "logcat_thread.h" #define EPOLL_MAX_EVENTS 10 LogcatThread::LogcatThread() { this->_epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (this->_epoll_fd == -1) { throw make_system_error("epoll_create1()"); } this->_thread = std::thread(&LogcatThread::_run, this); } LogcatThread::~LogcatThread() { if (this->_epoll_fd != -1 && close(this->_epoll_fd)) { log(std::string("Failed to close epoll file descriptor: ") + make_system_error("close()").what()); } } void LogcatThread::join() { this->_thread.join(); } void LogcatThread::_run() { struct epoll_event events[EPOLL_MAX_EVENTS]; // TODO break when run_main_loop is false while (true) { printf("(boop)\n"); int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000); if (ready_fds == -1) { printf("%s\n", format_log(make_system_error("epoll_wait()").what()).c_str()); break; } for (int i=0; i < ready_fds; i++) { printf("ain't no way in hell do we get a ready fd (#%d) when we haven't set up anything\n", i); } } }