logmeow/logcat_thread.cpp

40 lines
1.1 KiB
C++
Raw Normal View History

2023-01-16 09:10:53 +00:00
#include <unistd.h>
#include <sys/epoll.h>
#include "log.h"
#include "misc.h"
#include "logcat_thread.h"
#define EPOLL_MAX_EVENTS 10
LogcatThreadState::LogcatThreadState() {
this->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (this->epoll_fd == -1) {
throw make_system_error("epoll_create1()");
}
}
LogcatThreadState::~LogcatThreadState() {
if (close(this->epoll_fd)) {
log(std::string("Failed to close epoll file descriptor: ") + make_system_error("close()").what());
}
}
void run_logcat_thread(LogcatThreadState* state) {
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(state->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);
}
}
}