From b839dcaf1e5e11ce41b1e0e3d6c2d4d321fd236e Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 23 May 2002 09:48:22 +0000 Subject: iterator fix --- src/Timer.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Timer.cc b/src/Timer.cc index 876e53f..79b0939 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -128,22 +128,24 @@ void BTimer::updateTimers(int fd) { //must check end ...the timer might remove //it self from the list (should be fixed in the future) for(; it != m_timerlist.end(); ++it) { - tm.tv_sec = (*it)->getStartTime().tv_sec + - (*it)->getTimeout().tv_sec; - tm.tv_usec = (*it)->getStartTime().tv_usec + - (*it)->getTimeout().tv_usec; + //This is to make sure we don't get an invalid iterator + //when we do fireTimeout + BTimer &t = *(*it); + tm.tv_sec = t.getStartTime().tv_sec + + t.getTimeout().tv_sec; + tm.tv_usec = t.getStartTime().tv_usec + + t.getTimeout().tv_usec; if ((now.tv_sec < tm.tv_sec) || (now.tv_sec == tm.tv_sec && now.tv_usec < tm.tv_usec)) break; - (*it)->fireTimeout(); - + t.fireTimeout(); // restart the current timer so that the start time is updated - if (! (*it)->doOnce()) - (*it)->start(); - else { - (*it)->stop(); + if (! t.doOnce()) + t.start(); + else { + t.stop(); it--; } } -- cgit v0.11.2