CustomTargetsMgr::Pair_t CustomTargetsMgr::GetTarget(int menuId) const { if ( m_targets.count(menuId) ) { return m_targets.find(menuId)->second; } return Pair_t(); }
void ZSocketWatcher::pRun() { ZGuardMtx guard(fMtx); for (;;) { if (fSet.empty()) { // Nothing pending, wait 100ms in case something else comes along. fCnd.WaitFor(fMtx, 0.1); if (fSet.empty()) { // Still nothing pending, exit thread. fThreadRunning = false; break; } } else { fd_set readSet; FD_ZERO(&readSet); int largest = 0; foreachi (ii, fSet) { const int theFD = ii->first; if (largest < theFD) largest = theFD; FD_SET(ii->first, &readSet); } fd_set exceptSet; FD_COPY(&readSet, &exceptSet); struct timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0; guard.Release(); int count = ::select(largest + 1, &readSet, nullptr, &exceptSet, &timeout); guard.Acquire(); if (count < 1) { // Didn't get any continue; } // Gather the callables set<ZRef<ZCallable_Void> > toCall; for (int fd = 1; fd <= largest; ++fd) { if (FD_ISSET(fd, &readSet)) { --count; if (FD_ISSET(fd, &exceptSet)) --count; } else if (FD_ISSET(fd, &exceptSet)) --count; else continue; const Set_t::iterator iterBegin = fSet.lower_bound(Pair_t(fd, null)); Set_t::iterator iterEnd = iterBegin; const Set_t::iterator SetEnd = fSet.end(); while (iterEnd->first == fd and iterEnd != SetEnd) { toCall.insert(iterEnd->second); ++iterEnd; } fSet.erase(iterBegin, iterEnd); if (count <= 0) break; } guard.Release(); foreachi (ii, toCall) { try { (*ii)->Call(); } catch (...) {} } guard.Acquire(); } } }
bool ZSocketWatcher::QErase(int iSocket, const ZRef<ZCallable_Void>& iCallable) { return this->QErase(Pair_t(iSocket, iCallable)); }