Skip to content

Commit

Permalink
fixes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 6, 2024
1 parent 7ec47a8 commit 4d388c4
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions bee/filewatch/filewatch_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,29 @@ namespace bee::filewatch {
}

std::optional<notify> watch::select() noexcept {
if (m_inotify_fd == -1) {
return std::nullopt;
}
do {
if (m_inotify_fd == -1) {
break;
}

struct pollfd pfd_read;
pfd_read.fd = m_inotify_fd;
pfd_read.events = POLLIN;
if (poll(&pfd_read, 1, 0) != 1) {
return std::nullopt;
}
struct pollfd pfd_read;
pfd_read.fd = m_inotify_fd;
pfd_read.events = POLLIN;
if (poll(&pfd_read, 1, 0) != 1) {
break;
}

std::byte buf[4096];
ssize_t n = read(m_inotify_fd, buf, sizeof buf);
if (n == 0 || n == -1) {
return std::nullopt;
}
for (std::byte* p = buf; p < buf + n;) {
auto event = (struct inotify_event*)p;
event_update(event);
p += sizeof(*event) + event->len;
}
std::byte buf[4096];
ssize_t n = read(m_inotify_fd, buf, sizeof buf);
if (n == 0 || n == -1) {
break;
}
for (std::byte* p = buf; p < buf + n;) {
auto event = (struct inotify_event*)p;
event_update(event);
p += sizeof(*event) + event->len;
}
} while (false);

if (m_notify.empty()) {
return std::nullopt;
Expand Down

0 comments on commit 4d388c4

Please sign in to comment.