From 431544c9031d7268e409f6e30ac78ef7839bb304 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wpiutil/src/main/native/cpp/FileLogger.cpp b/wpiutil/src/main/native/cpp/FileLogger.cpp index 6e1435673b4..7d6ea6958e7 100644 --- a/wpiutil/src/main/native/cpp/FileLogger.cpp +++ b/wpiutil/src/main/native/cpp/FileLogger.cpp @@ -3,6 +3,8 @@ // the WPILib BSD license file in the root directory of this project. #include "wpi/FileLogger.h" +#include +#include #ifdef __linux__ #include @@ -10,11 +12,13 @@ #include #endif +#include #include #include #include #include +#include "wpi/print.h" #include "wpi/StringExtras.h" namespace wpi { @@ -28,13 +32,14 @@ FileLogger::FileLogger(std::string_view file, m_thread{[=, this] { char buf[4000]; 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)); + while (bufLen > 0) { callback(std::string_view{buf, static_cast(bufLen)}); + bufLen = read(m_fileHandle, buf, sizeof(buf)); } + std::this_thread::sleep_for(std::chrono::milliseconds(100)) } }} #endif