From c9b3d45d2598ebef2df889c0b9967ef473405528 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 9 Sep 2025 23:45:39 +0100 Subject: Use curl_multi_poll in main ingestLog loop Preparation step for having background curl operations. --- src/ingestor.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/ingestor.cpp') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 87167b5..6dd369e 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -58,7 +58,7 @@ namespace WebStat { } Ingestor::Ingestor(const utsname & host, DB::ConnectionPoolPtr dbpl) : - hostnameId {crc32(host.nodename)}, dbpool {std::move(dbpl)} + hostnameId {crc32(host.nodename)}, dbpool {std::move(dbpl)}, curl {curl_multi_init()} { auto dbconn = dbpool->get(); auto ins = dbconn->modify(SQL::HOST_UPSERT, SQL::HOST_UPSERT_OPTS); @@ -89,9 +89,18 @@ namespace WebStat { void Ingestor::ingestLog(std::FILE * input) { - while (auto line = scn::scan(input, "{:[^\n]}\n")) { - linesRead++; - ingestLogLine(dbpool->get().get(), line->value()); + curl_waitfd logIn {.fd = fileno(input), .events = CURL_WAIT_POLLIN, .revents = 0}; + + while (curl_multi_poll(curl.get(), &logIn, 1, INT_MAX, nullptr) == CURLM_OK) { + if (logIn.revents) { + if (auto line = scn::scan(input, "{:[^\n]}\n")) { + linesRead++; + ingestLogLine(dbpool->get().get(), line->value()); + } + else { + break; + } + } } } -- cgit v1.2.3