Skip to content

Commit

Permalink
IfwApiCheckTask: Drop superfluous CpuBoundWork usage
Browse files Browse the repository at this point in the history
All the places where the `CpuBoundWork` class was used only waste costly
semaphores, since they were either used to decode JSON responses and
process check results, which shouldn't take that much time worth
acquiring a semaphore.
  • Loading branch information
yhabteab committed Aug 28, 2024
1 parent a51910a commit a2c3540
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions lib/methods/ifwapichecktask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ static void ReportIfwCheckResult(
}
}

static void ReportIfwCheckResult(
boost::asio::yield_context yc, const Checkable::Ptr& checkable, const Value& cmdLine,
const CheckResult::Ptr& cr, const String& output, double start
)
{
double end = Utility::GetTime();
CpuBoundWork cbw (yc);

ReportIfwCheckResult(checkable, cmdLine, cr, output, start, end);
}

static const char* GetUnderstandableError(const std::exception& ex)
{
auto se (dynamic_cast<const boost::system::system_error*>(&ex));
Expand All @@ -108,9 +97,9 @@ static void DoIfwNetIo(
Connect(conn.lowest_layer(), psHost, psPort, yc);
} catch (const std::exception& ex) {
ReportIfwCheckResult(
yc, checkable, cmdLine, cr,
checkable, cmdLine, cr,
"Can't connect to IfW API on host '" + psHost + "' port '" + psPort + "': " + GetUnderstandableError(ex),
start
start, Utility::GetTime()
);
return;
}
Expand All @@ -121,10 +110,10 @@ static void DoIfwNetIo(
sslConn.async_handshake(conn.next_layer().client, yc);
} catch (const std::exception& ex) {
ReportIfwCheckResult(
yc, checkable, cmdLine, cr,
checkable, cmdLine, cr,
"TLS handshake with IfW API on host '" + psHost + "' (SNI: '" + san
+ "') port '" + psPort + "' failed: " + GetUnderstandableError(ex),
start
start, Utility::GetTime()
);
return;
}
Expand All @@ -139,10 +128,10 @@ static void DoIfwNetIo(
}

ReportIfwCheckResult(
yc, checkable, cmdLine, cr,
checkable, cmdLine, cr,
"Certificate validation failed for IfW API on host '" + psHost + "' (SNI: '" + san + "'; CN: "
+ (cn.IsString() ? "'" + cn + "'" : "N/A") + ") port '" + psPort + "': " + sslConn.GetVerifyError(),
start
start, Utility::GetTime()
);
return;
}
Expand All @@ -152,9 +141,9 @@ static void DoIfwNetIo(
conn.async_flush(yc);
} catch (const std::exception& ex) {
ReportIfwCheckResult(
yc, checkable, cmdLine, cr,
checkable, cmdLine, cr,
"Can't send HTTP request to IfW API on host '" + psHost + "' port '" + psPort + "': " + GetUnderstandableError(ex),
start
start, Utility::GetTime()
);
return;
}
Expand All @@ -163,9 +152,9 @@ static void DoIfwNetIo(
http::async_read(conn, buf, resp, yc);
} catch (const std::exception& ex) {
ReportIfwCheckResult(
yc, checkable, cmdLine, cr,
checkable, cmdLine, cr,
"Can't read HTTP response from IfW API on host '" + psHost + "' port '" + psPort + "': " + GetUnderstandableError(ex),
start
start, Utility::GetTime()
);
return;
}
Expand All @@ -177,7 +166,6 @@ static void DoIfwNetIo(
sslConn.async_shutdown(yc[ec]);
}

CpuBoundWork cbw (yc);
Value jsonRoot;

try {
Expand Down

0 comments on commit a2c3540

Please sign in to comment.