Skip to content

Commit cae7489

Browse files
Preserve sub-second precision when converting commandPowerOn timeout
Address review feedback: commandPowerOn previously mapped its std::chrono::duration<double> argument to timeval via duration_cast<seconds>, which truncates toward zero, and hardcoded tv_usec = 0. A caller passing e.g. 2.5 s would silently get a 2 s read timeout. Cast to microseconds (the smallest unit timeval can represent) and split into tv_sec + tv_usec so the fractional portion survives.
1 parent 63f1173 commit cae7489

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/ur/dashboard_client_implementation_x.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,12 @@ DashboardResponse DashboardClientImplX::commandPowerOn(const std::chrono::durati
245245
// The restore must run on every exit, including exceptions from inside put(), hence the
246246
// catch(...) rethrow guard.
247247
timeval configured_tv = getConfiguredReceiveTimeout();
248+
// Preserve sub-second precision: duration_cast<seconds> truncates fractional values,
249+
// so go via microseconds (the smallest unit timeval can represent) and split.
250+
const auto pwron_us = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
248251
timeval pwron_tv;
249-
pwron_tv.tv_sec = static_cast<time_t>(std::chrono::duration_cast<std::chrono::seconds>(timeout).count());
250-
pwron_tv.tv_usec = 0;
252+
pwron_tv.tv_sec = static_cast<time_t>(pwron_us.count() / 1'000'000);
253+
pwron_tv.tv_usec = static_cast<suseconds_t>(pwron_us.count() % 1'000'000);
251254
setReceiveTimeout(pwron_tv);
252255

253256
DashboardResponse response;

0 commit comments

Comments
 (0)