From 7af96ecb6463c356df241cbf8c5fa15fa54862c3 Mon Sep 17 00:00:00 2001 From: Jon Scheiding Date: Thu, 10 Jul 2025 17:46:16 -0400 Subject: [PATCH] Keep isFinished() false on StreamLog until stdin is closed --- seeklog.cpp | 33 ++++++++++++++++++++++++++++++++- seeklog.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/seeklog.cpp b/seeklog.cpp index 4dad928..acca991 100644 --- a/seeklog.cpp +++ b/seeklog.cpp @@ -32,6 +32,8 @@ #include #endif +#include + long long gSeekLogMaxBufferSize = 104857600; //StreamLog @@ -86,9 +88,38 @@ bool StreamLog::getNextLine(std::string& line) { return true; } +bool StreamLog::isPipeOpen() { + struct pollfd pfd; + pfd.fd = STDIN_FILENO; + pfd.events = POLLIN | POLLHUP; + + int ret = poll(&pfd, 1, 0); + + if(ret < 0) { + return false; + } + + if(ret == 0) { + return true; + } + + if(pfd.revents & POLLHUP) { + return false; + } +} + bool StreamLog::isFinished() { + if(fcntl_fail) { + return true; + } - if(fcntl_fail || stream->fail() || stream->eof()) { + #ifndef _WIN32 + if(isPipeOpen()) { + return false; + } + #endif + + if(stream->fail() || stream->eof()) { return true; } diff --git a/seeklog.h b/seeklog.h index 19abe6e..13d391c 100644 --- a/seeklog.h +++ b/seeklog.h @@ -58,6 +58,7 @@ class StreamLog : public BaseLog { bool getNextLine(std::string& line); bool isFinished(); + bool isPipeOpen(); }; class SeekLogException : public std::exception {