Commit cab8ad8b authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Fix bug: future/past should depend on the sign of the number of seconds

parent 212c8e91
......@@ -495,29 +495,26 @@ tao_timeout tao_get_absolute_timeout(
// `tao_time_member` overflow. We are assuming that current time since
// the Epoch is not near the limit +/-TAO_MAX_TIME_SECONDS.
double int_secs = floor(secs); // 0 ≤ secs - int_secs < 1s
tao_time_member abstime_s = abstime->sec;
tao_time_member abstime_ns = abstime->nsec + lround((secs - int_secs)*1e9);
TAO_NORMALIZE_TIME(tao_time_member, abstime_s, abstime_ns);
int_secs += (double)abstime_s;
if (int_secs >= 0) {
if (int_secs > (double)TAO_MAX_TIME_SECONDS) {
abstime->sec = TAO_MAX_TIME_SECONDS;
abstime->nsec = TAO_NANOSECONDS_PER_SECOND - 1;
return TAO_TIMEOUT_NEVER;
} else {
abstime->sec = (tao_time_member)int_secs;
abstime->nsec = abstime_ns;
return TAO_TIMEOUT_FUTURE;
}
tao_time_member s = 0;
tao_time_member ns = abstime->nsec + lround((secs - int_secs)*1e9);
TAO_NORMALIZE_TIME(tao_time_member, s, ns);
int_secs = (int_secs + (double)s) + (double)abstime->sec;
if (int_secs > (double)TAO_MAX_TIME_SECONDS) {
abstime->sec = TAO_MAX_TIME_SECONDS;
abstime->nsec = TAO_NANOSECONDS_PER_SECOND - 1;
return TAO_TIMEOUT_NEVER;
} else if (int_secs < (double)TAO_MIN_TIME_SECONDS) {
abstime->sec = TAO_MIN_TIME_SECONDS;
abstime->nsec = 0;
return TAO_TIMEOUT_PAST;
} else {
if (int_secs < (double)TAO_MIN_TIME_SECONDS) {
abstime->sec = TAO_MIN_TIME_SECONDS;
abstime->nsec = 0;
abstime->sec = (tao_time_member)int_secs;
abstime->nsec = ns;
if (secs >= 0) {
return TAO_TIMEOUT_FUTURE;
} else {
abstime->sec = (tao_time_member)int_secs;
abstime->nsec = abstime_ns;
return TAO_TIMEOUT_PAST;
}
return TAO_TIMEOUT_PAST;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment