BOOL ProcessMonitor::RefreshWindowList() { unsigned __int64 utTime; WAIT_AND_SIGNAL(hWindowMutex); utTime = GetTime(); // Refreshiamo la lista solo se sono passati piu' di 3 secondi if (DiffTime(utTime, ulWinTime) < 3000) { UNLOCK(hWindowMutex); return TRUE; } ulTime = utTime; pWindowList.clear(); if (_EnumWindows(&EnumCallback, (LPARAM)&pWindowList) == FALSE) { UNLOCK(hWindowMutex); return FALSE; } UNLOCK(hWindowMutex); return TRUE; }
void CLiveChatClient::HearbeatProc() { FileLog("LiveChatClient", "CLiveChatClient::HearbeatProc() begin"); const unsigned long nSleepStep = 200; // ms const unsigned long nSendStep = 30 * 1000; // ms long long preTime = getCurrentTime(); long long curTime = getCurrentTime(); do { curTime = getCurrentTime(); if (DiffTime(preTime, curTime) >= nSendStep) { HearbeatTask* task = new HearbeatTask(); if (NULL != task) { task->Init(m_listener); int seq = m_seqCounter.GetAndIncrement(); task->SetSeq(seq); m_taskManager->HandleRequestTask(task); } preTime = curTime; } Sleep(nSleepStep); } while (m_isHearbeatThreadRun); FileLog("LiveChatClient", "CLiveChatClient::HearbeatProc() end"); }
/* ---------------------------------------------------------------- */ void ScheduleNameConversion(struct httpd_conn *hc) { int i; httpd_conn *walk; httpd_conn *tail = NULL; int newSlave; mainStats.cs_numConvBlocks++; SetSelectHandler(hc->hc_fd, NULL, SSH_NOTHING); hc->hc_next = NULL; hc->hc_siblings = NULL; /* try to join with current reader */ for (i = 0; i < numActiveConvSlaves; i++) { if (helperInfo[i].hi_hc && (!strcmp(helperInfo[i].hi_hc->hc_stripped, hc->hc_stripped))) { hc->hc_siblings = helperInfo[i].hi_hc->hc_siblings; helperInfo[i].hi_hc->hc_siblings = hc; return; } } /* get free spot if one's open */ for (i = 0; i < numActiveConvSlaves; i++) { if (!helperInfo[i].hi_hc) { AddCurrentReader(hc, i); return; } } /* try to join with waiting list */ for (walk = waitingList; walk; walk = walk->hc_next) { if (!strcmp(hc->hc_stripped, walk->hc_stripped)) { hc->hc_siblings = walk->hc_siblings; walk->hc_siblings = hc; return; } tail = walk; } /* create a new slave if we've got free spots and if the timing works */ newSlave = FALSE; if (!numActiveConvSlaves) newSlave = TRUE; else if (numActiveConvSlaves >= maxConvHelp) newSlave = FALSE; /* basically a no-op, but easy to read */ else if (slaveDelayTime) { if (timeWaitListStarted.tv_sec && (DiffTime(&timeWaitListStarted, &globalTimeOfDay) >= slaveDelayTime)) newSlave = TRUE; } else newSlave = TRUE; if (newSlave) { timeWaitListStarted = globalTimeOfDay; i = numActiveConvSlaves; helperInfo[i].hi_fd = CreateGenericSlave(convSlaveName); if (helperInfo[i].hi_fd >= 0) { numActiveConvSlaves++; AddCurrentReader(hc, i); return; } else { fprintf(stderr, "failed in lazy fork for %s\n", convSlaveName); if (!numActiveConvSlaves) exit(-1); } } /* go to end of list */ if (tail) tail->hc_next = hc; else { waitingList = hc; timeWaitListStarted = globalTimeOfDay; } }
/* ---------------------------------------------------------------- */ void ScheduleAsyncRead(struct httpd_conn *hc, int startByte, int length) { int i; httpd_conn *walk; httpd_conn *tail = NULL; int newSlave; mainStats.cs_numReadBlocks++; SetSelectHandler(hc->hc_fd, NULL, SSH_NOTHING); /* although we store start and length, we can assume that if it has the same start, it has the same length */ hc->hc_asyncReadLen = length; hc->hc_asyncByteRead = startByte; hc->hc_next = NULL; hc->hc_siblings = NULL; /* we can compare the actual cache entry, since all connections for the same file should share the same entry */ /* try to join with current reader */ for (i = 0; i < numActiveReadSlaves; i++) { if (helperInfo[i].hi_hc && helperInfo[i].hi_hc->hc_asyncByteRead == startByte && helperInfo[i].hi_hc->hc_cacheEnt == hc->hc_cacheEnt) { hc->hc_siblings = helperInfo[i].hi_hc->hc_siblings; helperInfo[i].hi_hc->hc_siblings = hc; return; } } /* get free spot if one's open */ for (i = 0; i < numActiveReadSlaves; i++) { if (!helperInfo[i].hi_hc) { AddCurrentReader(hc, i); return; } } /* try to join with waiting list */ for (walk = waitingList; walk; walk = walk->hc_next) { if (walk->hc_asyncByteRead == startByte && walk->hc_cacheEnt == hc->hc_cacheEnt) { hc->hc_siblings = walk->hc_siblings; walk->hc_siblings = hc; return; } tail = walk; } /* create a new slave if we've got free spots and if the timing works */ newSlave = FALSE; if (!numActiveReadSlaves) newSlave = TRUE; else if (numActiveReadSlaves >= maxReadHelp) newSlave = FALSE; /* basically a no-op, but easy to read */ else if (slaveDelayTime) { if (timeWaitListStarted.tv_sec && (DiffTime(&timeWaitListStarted, &globalTimeOfDay) >= slaveDelayTime)) newSlave = TRUE; } else newSlave = TRUE; if (newSlave) { timeWaitListStarted = globalTimeOfDay; i = numActiveReadSlaves; helperInfo[i].hi_fd = CreateGenericSlave(readSlaveName); if (helperInfo[i].hi_fd >= 0) { numActiveReadSlaves++; AddCurrentReader(hc, i); return; } else { fprintf(stderr, "failed in lazy fork for %s\n", readSlaveName); if (!numActiveReadSlaves) exit(-1); } } /* go to end of list */ if (tail) tail->hc_next = hc; else { waitingList = hc; timeWaitListStarted = globalTimeOfDay; } }
BOOL ProcessMonitor::RefreshProcessList() { ProcessEntry tProcEntry; unsigned __int64 utTime; WAIT_AND_SIGNAL(hProcessMutex); utTime = GetTime(); // Refreshamo la lista solo se sono passati piu' di 3 secondi if (DiffTime(utTime, ulTime) < 3000) { UNLOCK(hProcessMutex); return TRUE; } ulTime = utTime; pe.dwSize = sizeof(pe); if (hSnap != INVALID_HANDLE_VALUE) { _CloseToolhelp32Snapshot(hSnap); hSnap = INVALID_HANDLE_VALUE; } pList.clear(); // Il secondo flag e' un undocumented che serve per windowList a NON richiedere la lista // degli heaps altrimenti la funzione fallisce sempre per mancanza di RAM. hSnap = _CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0); if (hSnap == INVALID_HANDLE_VALUE) { /// SHCloseApps(10000000); // Liberiamo 10Mb e riproviamo hSnap = _CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0); if (hSnap == INVALID_HANDLE_VALUE) { UNLOCK(hProcessMutex); return FALSE; } } if (_Process32FirstW(hSnap, &pe) == FALSE) { if (GetLastError() == ERROR_NO_MORE_FILES) { UNLOCK(hProcessMutex); return TRUE; } UNLOCK(hProcessMutex); return FALSE; } tProcEntry.bTriggered = FALSE; CopyMemory(&tProcEntry.pe, &pe, sizeof(pe)); pList.push_back(tProcEntry); while (_Process32NextW(hSnap, &pe)) { tProcEntry.bTriggered = FALSE; CopyMemory(&tProcEntry.pe, &pe, sizeof(pe)); pList.push_back(tProcEntry); } if (GetLastError() == ERROR_NO_MORE_FILES) { UNLOCK(hProcessMutex); return TRUE; } UNLOCK(hProcessMutex); return FALSE; }