1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 11:44:53 +08:00

fix timeouts handling on Unix systems (#142)

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-29 01:06:00 +03:00 committed by William Woodall
parent c16faab6ea
commit 4d69fb2e41

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;