Skip to content

Commit

Permalink
[wpiutil] Fix FileLogger only logging one byte at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Oct 3, 2024
1 parent f82e1c9 commit 973b3d8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions wpiutil/src/main/native/cpp/FileLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ FileLogger::FileLogger(std::string_view file,
m_inotifyWatchHandle{
inotify_add_watch(m_inotifyHandle, file.data(), IN_MODIFY)},
m_thread{[=, this] {
char buf[4000];
char buf[1000];
struct inotify_event ev;
int len = 0;
lseek(m_fileHandle, 0, SEEK_END);
while ((len = read(m_inotifyHandle, &ev, sizeof(ev))) > 0) {
int bufLen = 0;
if ((bufLen = read(m_fileHandle, buf, sizeof(buf)) > 0)) {
while (read(m_inotifyHandle, &ev, sizeof(ev) + NAME_MAX + 1) > 0) {
int bufLen = read(m_fileHandle, buf, sizeof(buf));
if (bufLen > 0) {
callback(std::string_view{buf, static_cast<size_t>(bufLen)});
}
}
Expand Down

0 comments on commit 973b3d8

Please sign in to comment.