Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions seeklog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <unistd.h>
#endif

#ifndef _WIN32
#include <poll.h>
#endif

long long gSeekLogMaxBufferSize = 104857600;

//StreamLog
Expand Down Expand Up @@ -95,6 +99,33 @@ bool StreamLog::isFinished() {
return false;
}

bool StreamLog::isOpen() {
if(fcntl_fail) return false;

#ifdef _WIN32
DWORD available_bytes;
if(!PeekNamedPipe(stdin_handle, 0, 0, 0, &available_bytes, 0)) {
return false;
}
return true;
#else
struct pollfd pfd;
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;

int ret = poll(&pfd, 1, 0);

if(ret < 0) return false;
if(ret == 0) return true;

if(pfd.revents & (POLLHUP | POLLERR | POLLNVAL)) {
return false;
}

return true;
#endif
}

// SeekLog

SeekLog::SeekLog(std::string logfile) {
Expand Down
2 changes: 2 additions & 0 deletions seeklog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BaseLog {
virtual ~BaseLog() {};
virtual bool getNextLine(std::string& line) { return false; };
virtual bool isFinished() { return false; };
virtual bool isOpen() { return !isFinished(); };
};

class StreamLog : public BaseLog {
Expand All @@ -58,6 +59,7 @@ class StreamLog : public BaseLog {

bool getNextLine(std::string& line);
bool isFinished();
bool isOpen();
};

class SeekLogException : public std::exception {
Expand Down