From: g0dil Date: Tue, 13 Nov 2007 14:58:50 +0000 (+0000) Subject: Socket/Protocols/Inet: Fix off-by-one error in INet6Address X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=44c966bc9d744d0926cffd5184fdb77a62564c16;p=senf.git Socket/Protocols/Inet: Fix off-by-one error in INet6Address PPI: Fix cloneSource unit-test packet construction Scheduler: BUGFIX: uninitialized loop variable Scheduler: BUGFIX: delay deletions in fdTable_ (can't change map while iterating over it) Add global 'valgrind' target Add 'valgrind.sup' suppressions file to suppress custom benign valgrind errors Fix all unit-tests to run correcly under valgrind (mostly timing adjustments) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@511 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/CloneSource.test.cc b/PPI/CloneSource.test.cc index 1b47375..14aeab5 100644 --- a/PPI/CloneSource.test.cc +++ b/PPI/CloneSource.test.cc @@ -40,7 +40,7 @@ BOOST_AUTO_UNIT_TEST(cloneSource) { - char data[] = { 0xAB }; + senf::PacketData::byte data[] = { 0xAB }; senf::Packet p (senf::DataPacket::create(data)); senf::ppi::module::CloneSource source (p); diff --git a/PPI/IntervalTimer.test.cc b/PPI/IntervalTimer.test.cc index f2e92e6..9aca3db 100644 --- a/PPI/IntervalTimer.test.cc +++ b/PPI/IntervalTimer.test.cc @@ -65,7 +65,7 @@ namespace { }; bool is_close_clock(senf::ClockService::clock_type a, senf::ClockService::clock_type b, - unsigned long delta = 50000000ul) + unsigned long delta = senf::ClockService::milliseconds(100)) { return (asecond.file); if (ev.events==0) { action = EPOLL_CTL_DEL; - fdTable_.erase(i); + fdErase_.push_back(fd); } if (! file && epoll_ctl(epollFd_, action, fd, &ev) < 0) @@ -161,7 +161,7 @@ prefix_ void senf::Scheduler::do_remove(int fd, int eventMask) prefix_ void senf::Scheduler::registerSigHandlers() { - for (unsigned signal; signal < sigHandlers_.size(); ++signal) + for (unsigned signal (1); signal < sigHandlers_.size(); ++signal) { if (sigHandlers_[signal]) { struct ::sigaction sa; sa.sa_sigaction = & Scheduler::sigHandler; @@ -172,6 +172,7 @@ prefix_ void senf::Scheduler::registerSigHandlers() if (::sigaction(signal, &sa, 0) < 0) throw SystemException(errno); } + } } prefix_ void senf::Scheduler::sigHandler(int signal, ::siginfo_t * siginfo, void *) @@ -214,6 +215,10 @@ prefix_ void senf::Scheduler::process() timerQueue_.pop(); } + for (FdEraseList::iterator i (fdErase_.begin()); i != fdErase_.end(); ++i) + fdTable_.erase(*i); + fdErase_.clear(); + int timeout (-1); if (files_ > 0) timeout = 0; @@ -258,11 +263,8 @@ prefix_ void senf::Scheduler::process() timerMap_.erase(i); } - if (events <= 0) - continue; - // Check the signal queue - if (ev.data.fd == sigpipe_[0]) { + if (events > 0 && ev.data.fd == sigpipe_[0]) { ::siginfo_t siginfo; if (::read(sigpipe_[0], &siginfo, sizeof(siginfo)) < int(sizeof(siginfo))) { // We ignore truncated records which may only occur if the signal @@ -276,25 +278,26 @@ prefix_ void senf::Scheduler::process() } for (FdTable::iterator i = fdTable_.begin(); i != fdTable_.end(); ++i) { - EventSpec spec (i->second); - unsigned extraFlags (0); - unsigned events (spec.file ? spec.epollMask() : ev.events); + EventSpec & spec (i->second); - if (! (spec.file || i->first == ev.data.fd)) + if (! (spec.file || (events > 0 && i->first == ev.data.fd))) continue; - if (events & EPOLLHUP) extraFlags |= EV_HUP; - if (events & EPOLLERR) extraFlags |= EV_ERR; + unsigned extraFlags (0); + unsigned mask (spec.file ? spec.epollMask() : ev.events); + + if (mask & EPOLLHUP) extraFlags |= EV_HUP; + if (mask & EPOLLERR) extraFlags |= EV_ERR; - if (events & EPOLLIN) { + if (mask & EPOLLIN) { BOOST_ASSERT(spec.cb_read); spec.cb_read(EventId(EV_READ | extraFlags)); } - else if (events & EPOLLPRI) { + else if (mask & EPOLLPRI) { BOOST_ASSERT(spec.cb_prio); spec.cb_prio(EventId(EV_PRIO | extraFlags)); } - else if (events & EPOLLOUT) { + else if (mask & EPOLLOUT) { BOOST_ASSERT(spec.cb_write); spec.cb_write(EventId(EV_WRITE | extraFlags)); } diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 4691e4a..94918af 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -351,6 +351,7 @@ namespace senf { typedef std::map FdTable; typedef std::map TimerMap; // sorted by id + typedef std::vector FdEraseList; # ifndef DOXYGEN @@ -371,6 +372,7 @@ namespace senf { typedef std::vector SigHandlers; FdTable fdTable_; + FdEraseList fdErase_; unsigned files_; unsigned timerIdCounter_; diff --git a/Scheduler/Scheduler.test.cc b/Scheduler/Scheduler.test.cc index c26b640..2bc2a32 100644 --- a/Scheduler/Scheduler.test.cc +++ b/Scheduler/Scheduler.test.cc @@ -186,7 +186,7 @@ namespace { bool is_close(ClockService::clock_type a, ClockService::clock_type b) { - return (a