1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-23 04:04:54 +08:00

fix timeouts handling on Unix systems

fixed "singed long" overflow that took place on attempt
to use ~3000ms or bigger timeouts on Unix systems
This commit is contained in:
Aleksey Sergey 2016-11-10 01:13:11 +03:00
parent d76b7d6b7f
commit 3fa0c92456

View File

@ -62,7 +62,7 @@ MillisecondTimer::MillisecondTimer (const uint32_t millis)
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6); int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
if (tv_nsec >= 1e9) { if (tv_nsec >= 1e9) {
int64_t sec_diff = tv_nsec / static_cast<int> (1e9); int64_t sec_diff = tv_nsec / static_cast<int> (1e9);
expiry.tv_nsec = tv_nsec - static_cast<int> (1e9 * sec_diff); expiry.tv_nsec %= static_cast<int>(1e9);
expiry.tv_sec += sec_diff; expiry.tv_sec += sec_diff;
} else { } else {
expiry.tv_nsec = tv_nsec; expiry.tv_nsec = tv_nsec;