From d64ecc38cbb312ddc5017e542619ea059c845fdd Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:26:10 -0400 Subject: [PATCH] [wpiutil] Fix FileLogger only logging one byte at a time --- wpiutil/src/main/native/cpp/FileLogger.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wpiutil/src/main/native/cpp/FileLogger.cpp b/wpiutil/src/main/native/cpp/FileLogger.cpp index 6e1435673b4..4b7bf63258e 100644 --- a/wpiutil/src/main/native/cpp/FileLogger.cpp +++ b/wpiutil/src/main/native/cpp/FileLogger.cpp @@ -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[2000]; 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)) > 0) { + int bufLen = read(m_fileHandle, buf, sizeof(buf)); + if (bufLen > 0) { callback(std::string_view{buf, static_cast(bufLen)}); } }