Skip to content

Commit

Permalink
Fixed some feature envy.
Browse files Browse the repository at this point in the history
Change-Id: I221154e9dc075a8d6bfcdf94e90c80b1ceda456d
  • Loading branch information
spt29 committed Nov 21, 2023
1 parent 7c54d46 commit abc3bcc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/livestatus/include/livestatus/InputBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class InputBuffer {
std::chrono::milliseconds query_timeout,
std::chrono::milliseconds idle_timeout);
Result readRequest();
[[nodiscard]] bool empty() const;
std::string nextLine();
std::list<std::string> getLines();

private:
const int _fd;
Expand Down
13 changes: 11 additions & 2 deletions packages/livestatus/src/InputBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,19 @@ InputBuffer::Result InputBuffer::readData() {
return Result::should_terminate;
}

bool InputBuffer::empty() const { return _request_lines.empty(); }

std::string InputBuffer::nextLine() {
std::string s = _request_lines.front();
_request_lines.pop_front();
return s;
}

std::list<std::string> InputBuffer::getLines() {
std::list<std::string> lines;
while (!_request_lines.empty()) {
lines.push_back(nextLine());
if (lines.back().empty()) {
break;
}
}
return lines;
}
15 changes: 1 addition & 14 deletions packages/neb/src/NebCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,19 +619,6 @@ bool NebCore::pnp4nagiosEnabled() const {
return true; // TODO(sp) ???
}

namespace {
std::list<std::string> getLines(InputBuffer &input) {
std::list<std::string> lines;
while (!input.empty()) {
lines.push_back(input.nextLine());
if (lines.back().empty()) {
break;
}
}
return lines;
}
} // namespace

void NebCore::logRequest(const std::string &line,
const std::list<std::string> &lines) {
Informational log(_logger);
Expand Down Expand Up @@ -687,7 +674,7 @@ bool NebCore::answerRequest(InputBuffer &input, OutputBuffer &output) {
bool NebCore::handleGet(InputBuffer &input, OutputBuffer &output,
const std::string &line,
const std::string &table_name) {
auto lines = getLines(input);
auto lines = input.getLines();
logRequest(line, lines);
return _store.answerGetRequest(lines, output, table_name);
}
Expand Down

0 comments on commit abc3bcc

Please sign in to comment.