Skip to content

Commit

Permalink
Refactor next_line to return timeout indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiklohmann committed Apr 23, 2020
1 parent 85d0a3e commit 4708e51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
13 changes: 7 additions & 6 deletions libvast/src/format/csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,14 @@ caf::error reader::read_impl(size_t max_events, size_t max_slice_size,
consumer& callback) {
VAST_ASSERT(max_events > 0);
VAST_ASSERT(max_slice_size > 0);
bool timeout = false;
auto next_line = [&] {
if (!builder_ || builder_->rows() == 0)
if (!builder_ || builder_->rows() == 0) {
lines_->next();
else
timeout = lines_->next_timeout(
return false;
} else {
return lines_->next_timeout(
vast::defaults::import::shared::partial_slice_read_timeout);
}
};
if (!parser_) {
auto p = read_header(lines_->get());
Expand All @@ -425,8 +426,8 @@ caf::error reader::read_impl(size_t max_events, size_t max_slice_size,
parser_ = *std::move(p);
}
auto& p = *parser_;
next_line();
for (size_t produced = 0; produced < max_events; next_line()) {
bool timeout = next_line();
for (size_t produced = 0; produced < max_events; timeout = next_line()) {
if (timeout) {
VAST_DEBUG(this, "reached input timeout at line", lines_->line_number());
return finish(callback);
Expand Down
10 changes: 6 additions & 4 deletions libvast/src/format/syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ reader::read_impl(size_t max_events, size_t max_slice_size, consumer& f) {
bool timeout = false;
table_slice_builder_ptr bptr = nullptr;
auto next_line = [&] {
if (!bptr || bptr->rows() == 0)
if (!bptr || bptr->rows() == 0) {
lines_->next();
else
timeout = lines_->next_timeout(
return false;
} else {
return lines_->next_timeout(
vast::defaults::import::shared::partial_slice_read_timeout);
}
};
for (size_t produced = 0; produced < max_events; next_line()) {
for (size_t produced = 0; produced < max_events; timeout = next_line()) {
if (timeout) {
VAST_DEBUG(this, "reached input timeout at line", lines_->line_number());
return finish(f);
Expand Down
10 changes: 6 additions & 4 deletions libvast/vast/format/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ caf::error reader<Selector>::read_impl(size_t max_events, size_t max_slice_size,
table_slice_builder_ptr bptr = nullptr;
bool timeout = false;
auto next_line = [&] {
if (!bptr || bptr->rows() == 0)
if (!bptr || bptr->rows() == 0) {
lines_->next();
else
timeout = lines_->next_timeout(
return false;
} else {
return lines_->next_timeout(
vast::defaults::import::shared::partial_slice_read_timeout);
}
};
for (; produced < max_events; next_line()) {
for (; produced < max_events; timeout = next_line()) {
if (timeout) {
VAST_DEBUG(this, "reached input timeout at line", lines_->line_number());
return finish(cons);
Expand Down

0 comments on commit 4708e51

Please sign in to comment.