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
33 changes: 32 additions & 1 deletion seeklog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <unistd.h>
#endif

#include <poll.h>

long long gSeekLogMaxBufferSize = 104857600;

//StreamLog
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions seeklog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class StreamLog : public BaseLog {

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

class SeekLogException : public std::exception {
Expand Down