It currently won't ever be called with an empty list of timers, but it
is a public function so that might happen in the future. Make sure this
case is handled without crashes.
int Timer::getNextTimeout() {
timeval now;
gettimeofday(&now, 0);
+
+ if (pending.empty())
+ return -1;
+
int toWait = pending.front()->getRemainingMs();
+
if (toWait > pending.front()->timeoutMs) {
if (toWait - pending.front()->timeoutMs < 1000) {
vlog.info("gettimeofday is broken...");
pending.front()->dueTime = now;
toWait = 0;
}
+
return toWait;
}