summaryrefslogtreecommitdiff
path: root/src/voltronic
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-17 14:28:04 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-17 14:28:04 +0300
commit9e6930b2fe836f240de8ac78c03d54e7f0214122 (patch)
treecb018e351588a9da2d00211d4b3e90e8b4e7cffb /src/voltronic
parentd50de2735d4af1056f0301ba99c40aac082bad27 (diff)
device: fix timeout logic when Device is reused
Diffstat (limited to 'src/voltronic')
-rw-r--r--src/voltronic/device.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/voltronic/device.cc b/src/voltronic/device.cc
index 632ed27..eb332eb 100644
--- a/src/voltronic/device.cc
+++ b/src/voltronic/device.cc
@@ -33,7 +33,6 @@ void Device::setVerbose(bool verbose) {
void Device::setTimeout(u64 timeout) {
timeout_ = timeout;
- timeStarted_ = timestamp();
}
u64 Device::getElapsedTime() const {
@@ -44,10 +43,16 @@ u64 Device::getTimeLeft() const {
if (!timeout_)
return std::numeric_limits<uint64_t>::max();
- return std::max((u64)0, timeout_ - getElapsedTime());
+ u64 elapsed = getElapsedTime();
+ if (elapsed > timeout_)
+ return 0;
+
+ return timeout_ - elapsed;
}
size_t Device::run(const u8* inbuf, size_t inbufSize, u8* outbuf, size_t outbufSize) {
+ timeStarted_ = timestamp();
+
send(inbuf, inbufSize);
if (!getTimeLeft())