STDMETHODIMP MemChecker::Func() { switch (m_state) { case ALLOC_OFF: if (m_bOnce) { SharedMemory::checkleaks(); SharedMemory::resetleaks(); } else { SharedMemory::setogredebug(TRUE); SharedMemory::resetleaks(); } m_bOnce = TRUE; m_state = ALLOC_ON; /* 20 mins */ m_pProc->pc->engine->schedule.enter(m_pProc->pc->engine->now + Timeval((double)(g_ulLeakCheckAlloc * 60)), this); break; case ALLOC_ON: m_state = ALLOC_OFF; /* 40 mins */ m_pProc->pc->engine->schedule.enter(m_pProc->pc->engine->now + Timeval((double)(g_ulLeakCheckFree * 60)), this); SharedMemory::suspendleaks(); break; } return HXR_OK; }
MemChecker::MemChecker(Process* pProc) { m_pProc = pProc; m_state = ALLOC_OFF; m_bOnce = FALSE; /* 1/2 hour */ m_pProc->pc->engine->schedule.enter(m_pProc->pc->engine->now + Timeval((double)(g_ulLeakCheckFirst * 60)), this); }
InterfaceStore::size_type InterfaceStore::age(const InterfaceRef &parent, InterfaceRefList *ifl, Timeval *lifetime) { Mutex::AutoLocker l(mutex); InterfaceRefList children; size_type removed = 0; // Initialize the lifetime to an "invalid" number if (lifetime) *lifetime = Timeval(-1); InterfaceStore::iterator it = begin(); while (it != end()) { InterfaceRecord *ir = *it; if ((ir->iface->isLocal() && !parent) || (parent && ir->parent && ir->parent == parent && !ir->iface->isSnooped())) { if (ir->cip->isDead()) { if (ifl) ifl->add(ir->iface); removed++; ir->iface->resetFlag(IFFLAG_STORED); it = erase(it); children.push_front(ir->iface); delete ir; continue; } ir->cip->age(); if (lifetime && ir->cip->lifetime().isValid()) { if (!lifetime->isValid() || ir->cip->lifetime() < *lifetime) { *lifetime = ir->cip->lifetime(); } } } it++; } while (!children.empty()) { removed += remove_children(children.pop(), ifl); } return removed; }
CRN1CloakGETHandler::OnDispatch(void) { AddRef(); CBaseCloakGETHandler::OnDispatch(); if (m_pConn && m_pConn->GetPOSTHandlerCount() > 0) { // The POST connection has already arrived. Tell the player to use // single-POST mode. sendResponseHeader(RN_HEADER_CONTENT_TYPE); sendPostStatus(HTTP_CLOAK_OK); CBaseCloakPOSTHandler* pPOSTHandler = 0; // just in case the socket writes failed if (m_pConn && m_pConn->GetPOSTHandlerCount() > 0) { m_pConn->GetFirstPOSTHandler(pPOSTHandler); if (pPOSTHandler) { pPOSTHandler->ProcessPendingData(); pPOSTHandler->Release(); } } } else { // The POST connection has not arrived yet. Schedule a callback for // one second. If the callback fires and the POST has not arrived, // assume the POST got trapped by a firewall and we tell the player // to use multi-POST mode. m_pPostCB = new PostCallback(this, m_pProc); m_pPostCB->AddRef(); m_ulPostCbId = m_pProc->pc->engine->schedule.enter(m_pProc->pc->engine->now + Timeval(1.0), m_pPostCB); } Release(); }
STDMETHODIMP BasicPacketFlow::OnPacket(UINT16 uStreamNumber, BasePacket** ppPacket) { if (m_bIsDone) return HXR_UNEXPECTED; PacketStream* pStream = &m_pStreams[uStreamNumber]; HX_ASSERT(pStream->m_bStreamRegistered); BasePacket* pPacket; for (; (pPacket = *ppPacket); ppPacket++) { // Do not check for IsStreamDone() because this is part of the // resend mechanism if (pPacket->IsResendRequested() && pPacket->m_uPriority != 10) continue; if (!pPacket->IsResendRequested()) pPacket->SetResendRequested(); UINT32 ulPos = m_ulResendIDPosition + 1; if (ulPos == MAX_RESENDS_PER_SECOND) ulPos = 0; while (m_pResendIDs[ulPos] && ulPos != m_ulResendIDPosition) { ulPos++; if (ulPos == MAX_RESENDS_PER_SECOND) ulPos = 0; } if (m_pResendIDs[m_ulResendIDPosition = ulPos]) continue; PacketFlowResendCallback* pResendCB = new (m_pProc->pc->mem_cache) PacketFlowResendCallback(); pResendCB->AddRef(); pResendCB->m_pTransport = pStream->m_pTransport; pResendCB->m_pPacket = pPacket; pResendCB->m_pPacket->AddRef(); pResendCB->m_pZeroMe = m_pResendIDs + m_ulResendIDPosition; UINT32 ulMinWaitTime; if ((m_pRateManager) && (m_pRateManager->GetActualDeliveryRate() > 60000)) ulMinWaitTime = 500; else ulMinWaitTime = 10; UINT32 ulTime = rand() % 300 + ulMinWaitTime; // printf("%p %p %p %p %p\n", this, m_pProc, m_pProc->pc, m_pProc->pc->engine, // m_pProc->pc->engine->schedule); // fflush(stdout); m_pResendIDs[m_ulResendIDPosition] = m_pProc->pc->engine->schedule.enter( m_pProc->pc->engine->now + Timeval(0, ulTime * 1000), pResendCB); pResendCB->Release(); } return HXR_OK; }
void MiscProcessInitCallback::func(Process* proc) { PluginHandler::Errors plugin_result; IUnknown* instance; MiscProcessInitCallback::Errors result = NO_ERRORS; HX_RESULT h_result = 0; IHXPlugin* plugin_interface; char temp[512]; MiscContainer* pMCont; proc->pc = pMCont = new MiscContainer(proc, m_proc->pc); proc->pc->dispatchq->init(proc); proc->pc->process_type = PTMisc; pMCont->m_plugin = m_plugin; /* * Now that the proc->pc is established, it is safe to initialize the * IHXNetworkServicesContext */ proc->pc->network_services->Init(proc->pc->server_context, proc->pc->engine, NULL); proc->pc->net_services->Init(proc->pc->server_context); if (g_bPrintProcessPIDs) { sprintf(temp, "Loading %s %d: %-.256s", m_plugin->m_load_multiple ? "MultiLoad" : "Non-MultiLoad", proc->procid(proc->procnum()), m_plugin->m_pszDescription); proc->pc->error_handler->Report(HXLOG_DEBUG, 0, 0, temp, 0); // Output to startup log... if (g_bUseStartupLog) { FILE *fp = fopen(g_szStartupLog, "a"); if (fp) { fprintf(fp, "D: %s\n", temp); fclose(fp); } } } plugin_result = m_plugin->GetInstance(&instance); if (PluginHandler::NO_ERRORS != plugin_result) { result = BAD_PLUGIN; ERRMSG(proc->pc->error_handler, "Bad Misc plugin\n"); m_plugin->ReleaseInstance(); // XXXSMP Need Proper Exit Code!! *pMiscProcInitMutex = 0; exit(0); } if (NO_ERRORS == result) { h_result = instance->QueryInterface(IID_IHXPlugin, (void **)&plugin_interface); if (HXR_OK == h_result) { MiscProcInitPlug* pMisc = new MiscProcInitPlug(proc); plugin_interface->InitPlugin(proc->pc->server_context); pMisc->instance = instance; pMisc->instance->AddRef(); pMisc->plugin_interface = plugin_interface; pMisc->pMPI = this; pMisc->m_pAcceptor = m_pAcceptor; pMCont->m_pInstance = (IUnknown*)plugin_interface; proc->pc->engine->schedule.enter(Timeval(0.0), pMisc); } else { printf ("Misc Plugin Failed to Init correctly\n"); } } m_plugin->m_process = proc; m_plugin->ReleaseInstance(); instance->Release(); *pMiscProcInitMutex = 0; if (NO_ERRORS != result) return; proc->pc->engine->mainloop(); }