diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 6d5b0a957acaf28bf21f152ea0b2bb2c94ef6d25..af0539b4fba630da88b9bc17250ea27779151fb4 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -139,9 +139,7 @@ bool HilogBuffer::Query(std::shared_ptr reader) } if (reader->isNotified) { - if (reader->lastPos == hilogDataList.end()) { - reader->readPos = std::prev(reader->lastPos); - } else { + if (reader->readPos == hilogDataList.end()) { reader->readPos = std::next(reader->lastPos); } } @@ -173,13 +171,12 @@ bool HilogBuffer::Query(std::shared_ptr reader) printLenByDomain[reader->readPos->domain] += strlen(reader->readPos->content); } reader->readPos++; - reader->isNotified = false; hilogBufferMutex.unlock(); return true; } reader->readPos++; } - + reader->isNotified = false; ReturnNoLog(reader); hilogBufferMutex.unlock(); return false; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 62ff430051dd050abe004aa9fc766d8c59f73237..94c4041f457a7b9c5ae1a68547d4d9d47c952b9f 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -544,14 +544,17 @@ int LogQuerier::WriteData(HilogData* data) void LogQuerier::NotifyForNewData() { + if (isNotified) { + return; + } + isNotified = true; LogQueryResponse rsp; rsp.data.sendId = SENDIDS; rsp.data.type = -1; /* set header */ SetMsgHead(&(rsp.header), NEXT_RESPONSE, sizeof(rsp)); - int ret = WriteData(rsp, nullptr); - if (ret > 0) { - isNotified = true; + if ( WriteData(rsp, nullptr) <= 0) { + isNotified = false; } }