Beispiel #1
0
DWORD CService::WatcherThreadMemberProc()
{
   DWORD dwWait = 0;
   bool bControlWait = true;

   // Wait for any events to signal
   while(bControlWait)
   {
      dwWait = WaitForMultipleObjects(NUMEVENTS, m_hEvents, FALSE, INFINITE);

      switch(dwWait - WAIT_OBJECT_0)
      {
      case STOP:
         OnStop();
         bControlWait = false;
         break;

      case PAUSE:
         OnPause();
         ResetEvent(m_hEvents[PAUSE]);
         break;

      case CONTINUE:
         OnContinue();
         ResetEvent(m_hEvents[CONTINUE]);
         break;

      case SHUTDOWN:
         OnShutdown();
         bControlWait = false;
         break;
      }
   }
   return 0;
}
/*++

Routine Description:

    The function executes when the system is shutting down. It
    calls the OnShutdown virtual function in which you can specify what
    should occur immediately prior to the system shutting down. If an error
    occurs, the error will be logged in the Application event log.

Arguments:

    VOID

Return Value:

    VOID

--*/
VOID
CServiceBase::Shutdown()
{
    try
    {
        //
        // Perform service-specific shutdown operations.
        //
        OnShutdown();

        //
        // Tell SCM that the service is stopped.
        //
        SetServiceStatus(SERVICE_STOPPED);
    }
    catch (DWORD Error)
    {
        //
        // Log the error.
        //
        WriteToErrorLog(L"Service Shutdown", Error);
    }
    catch (...)
    {
        //
        // Log the error.
        //
        WriteToEventLog(L"Service failed to shut down.", EVENTLOG_ERROR_TYPE);
    }
}
Beispiel #3
0
bool LinkageWorker::Run()
{
    if (!OnInitialize()) {
        return false;
    }

    HealthTimer *health = new HealthTimer(this);
    if (!RegisterTimer(1000000000LL, health, true)) {
        delete health;
        return false;
    }

    bool result = true;
    while (!_quit) {
        if (!ev_run(_loop, 0)) {
            CLOG.Error("Linkage: ev_run() returned false.");
            result = false;
            break;
        }
    }

    OnShutdown();

    for (events_t::iterator p = _events.begin(); p != _events.end(); ++p) {
        DoRelease(p->second, false);
    }

    for (timers_t::iterator p = _timers.begin(); p != _timers.end(); ++p) {
        DoRelease(*p, false);
    }

    _events.clear();
    _timers.clear();
    return result;
}
Beispiel #4
0
void Service::Run()
{
    // We use a message loop here because this is arguably the easiest
    // way to deal with the potential race conditions that exist between
    // the service thread and the handler thread.  The SCM will make no
    // provisions for synchronizing status activity, the best bet is to
    // ensure that all calls are handled through the service main thread.
    MSG msg;
    while (GetMessage(&msg, NULL, WM_USER, WM_USER) > 0) {
        WPARAM opcode = msg.wParam;
        if (opcode == SERVICE_CONTROL_STOP) {
            SetStatus(SERVICE_STOP_PENDING);
            OnStop();
            break;
        }
        else if (opcode == SERVICE_CONTROL_PAUSE) {
            OnPause();
        }
        else if (opcode == SERVICE_CONTROL_CONTINUE) {
            OnContinue();
        }
        else if (opcode == SERVICE_CONTROL_INTERROGATE) {
            OnInterrogate();
        }
        else if (opcode == SERVICE_CONTROL_SHUTDOWN) {
            OnShutdown();
        }
        ::SetServiceStatus(m_pThis->m_hServiceStatus, &m_pThis->m_Status);
    }
}
NS_IMETHODIMP 
sbBaseMediacore::Shutdown()
{
  TRACE(("sbBaseMediacore[0x%x] - Shutdown", this));
  NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);

  return OnShutdown();
}
void CMainApp::ExitInstance()
{
	the_log.LogT(1, "ExitInstance:\n");
	the_log.LogT(4, "ExitInstance: OnShutdown call...\n");
	OnShutdown();
	CoUninitialize();
//	Sleep(1000);
	the_log.LogT(2, "ExitInstance: DONE\n");
	
}
LRESULT GameBase::MessageHandler( UINT msg, WPARAM wparam, LPARAM lparam )
{
    switch (msg)
    {
    case WM_CLOSE:
        DestroyWindow( m_hwnd );
        break;

    case WM_DESTROY:
        OnShutdown();
        PostQuitMessage(0);
        break;

    case WM_KEYDOWN:
        if (!(lparam & 0x40000000)) // Prevent auto-repeat
        {
            OnKeyDown( wparam );
        }
        break;

    case WM_KEYUP:
        OnKeyUp( wparam );
        break;

    case WM_LBUTTONDOWN:
        OnStylusDown( Point( LOWORD(lparam), HIWORD(lparam) ) );
        break;

    case WM_LBUTTONUP:
        OnStylusUp( Point( LOWORD(lparam), HIWORD(lparam) ) );
        break;

    case WM_MOUSEMOVE:
        OnStylusMove( Point( LOWORD(lparam), HIWORD(lparam) ) );
        break;

	case WM_ACTIVATE:
		if (LOWORD(wparam) == WA_INACTIVE)
		{
            m_bSuspended = true;
			OnSuspend();
		}
		else
		{
            m_bSuspended = false;
			OnResume();
		}
		break;
    }

    return DefWindowProc( m_hwnd, msg, wparam, lparam );
}
Beispiel #8
0
int CMraProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
	switch (eventType) {
	case EV_PROTO_ONLOAD:    return OnModulesLoaded(0, 0);
	case EV_PROTO_ONEXIT:    return OnShutdown(0, 0);
	case EV_PROTO_ONOPTIONS: return OnOptionsInit(wParam, lParam);

	case EV_PROTO_ONMENU:
		CListCreateMenu(2000060000, 500085000, TRUE, gdiMenuItems, MAIN_MENU_ITEMS_COUNT, hMainMenuItems);
		break;
	}
	return 1;
}
Beispiel #9
0
void UGame::Shutdown()
{
	if ( IsPendingKill() )
	{
		return;
	}

	OnShutdown();

	ObjectTree->Dispose();

	MarkPendingKill();
}
Beispiel #10
0
DWORD Service::_HandlerEx(DWORD dwOpcode,DWORD dwEventType,LPVOID lpEventData,LPVOID lpContext)
{
	m_dbgMsg(L"Service::Handler(%lu)", dwOpcode);
    switch (dwOpcode) {
    case SERVICE_CONTROL_STOP: // 1
        SetStatus(SERVICE_STOP_PENDING);
        OnStop();
        m_bIsRunning = FALSE;
		EVLOG_INFO(EVMSG_STOPPED);
        break;

    case SERVICE_CONTROL_PAUSE: // 2
        OnPause();
        break;

    case SERVICE_CONTROL_CONTINUE: // 3
        OnContinue();
        break;

    case SERVICE_CONTROL_INTERROGATE: // 4
        OnInterrogate();
        break;

    case SERVICE_CONTROL_SHUTDOWN: // 5
        OnShutdown();
        break;

    case SERVICE_CONTROL_DEVICEEVENT:
        OnDeviceEvent(dwEventType,lpEventData);
        break;

    default:
        if (dwOpcode >= SERVICE_CONTROL_USER) {
            if (!OnUserControl(dwOpcode)) {
				EVLOG_ERROR(EVMSG_BADREQUEST);
            }
        } else {
            EVLOG_ERROR(EVMSG_BADREQUEST);
        }
        break;
    }

    // Report current status
	m_dbgMsg(L"Updating status (%lu, %lu)", m_hServiceStatus, m_Status.dwCurrentState);

    ::SetServiceStatus(m_hServiceStatus, &m_Status);

#ifdef HANDLEREX
    return NO_ERROR;
#endif HANDLEREX
}
// The function executes when the system is shutting down. It calls OnShutdown
// virtual function.
void GServiceBase::Shutdown() {
  try {
    // Perform service-specific shutdown operations.
    OnShutdown();

    // Tell SCM that the service is stopped.
    SetServiceStatus(SERVICE_STOPPED);
  } catch (DWORD error) {
    WriteErrorLogEntry(L"Service Shutdown", error);
  } catch (...) {
    WriteErrorLogEntry(
        L"Service Shutdown.", GetLastError());
  }
}
Beispiel #12
0
void mpStartup::Shutdown()
{
  if(g_bIsShutDown)
    return;

  MP_Assert(g_bIsStarted, "Cannot shut down when we are not started!");

  for (auto pInit = g_pInit; pInit != nullptr; pInit = pInit->m_pNext)
  {
    pInit->OnShutdown();
  }

  g_bIsShutDown = true;
}
Beispiel #13
0
bool ServiceBase::OnCommand(DWORD dwControl, DWORD dwEventType, void *lpEventData) {
	TRC(2, ServiceName << ": " << ServiceControlToString(dwControl));

	switch (dwControl) {
	case SERVICE_CONTROL_STOP:
		Stop();
		break;
	case SERVICE_CONTROL_SHUTDOWN:
		Status = SERVICE_STOP_PENDING;
		OnShutdown();
		break;
	case SERVICE_CONTROL_PAUSE:
		Status = SERVICE_PAUSE_PENDING;
		OnPause();
		break;
	case SERVICE_CONTROL_CONTINUE:
		Status = SERVICE_CONTINUE_PENDING;
		OnContinue();
		break;
	case SERVICE_CONTROL_INTERROGATE:
		Status = m_status;
		break;
	case SERVICE_CONTROL_POWEREVENT:
		OnPowerEvent((PowerBroadcastStatus)dwEventType);
		break;
	case SERVICE_CONTROL_SESSIONCHANGE:
		{
			SessionChangeDescription scd = { (SessionChangeReason)dwEventType, (int)((WTSSESSION_NOTIFICATION*)lpEventData)->dwSessionId };
			TRC(2, ReasonToString(scd.Reason));
			OnSessionChange(scd);
		}
		break;
	case SERVICE_CONTROL_PARAMCHANGE:
		OnParamChange();
		break;
	case SERVICE_CONTROL_TIMECHANGE:
		OnTimeChange();
		break;
	case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
		OnHardwareProfileChange();
		break;
	default:
		if (dwControl >= 128 && dwControl <= 255)
			OnCustomCommand(dwControl);
		else
			return false;
	}
	return true;
}
Beispiel #14
0
/* Window proc for poweroff event */
static DWORD CALLBACK MessageWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_ENDSESSION:
		log_debugA("WM_ENDSESSION");
		if (wParam) {
			log_debugA("WM_ENDSESSION: calling exit");
			OnShutdown(0, 0);
			log_debugA("WM_ENDSESSION: exit called");
		}
		break;
	}

	return TRUE;
}
Beispiel #15
0
void App::Shutdown()
{
	d_printf("-: On Shutdown...");
	OnShutdown();

	d_printf("-: Engine Shutdown...");
	delete mIME;
	delete mDebugInfo;
	delete mParticleFX;
	delete mPhyWorld;
	delete mWorld;
	delete mUIEngine;
	delete mAudioSystem;
	delete mRenderSystem;
	delete mRoot;

	d_printf("-: Shutdown OK...");
}
Beispiel #16
0
bool Lacrimi::run()
{
    Delay(400);
    if(GetConfigBool("Features", "LuaEngine", true))
    {
        L_LuaEngineMgr = new LuaEngineMgr();
        L_LuaEngineMgr->Startup();
        Delay(100);
        while(LuaEngineIsStarting)
            Delay(100);
    }

    uint32 curTime = getMSTime();
    uint32 m_StatDumpTimer = curTime+15000, m_CleanupDelay = curTime+10000;
    while(GetThreadState() != THREADSTATE_SELF_TERMINATE)
    {
        curTime = getMSTime();
        if(!SetThreadState(THREADSTATE_BUSY))
            break;

        if(dumpstats)
        {
            if(curTime > m_StatDumpTimer)
            {
                DumpStats();
                m_StatDumpTimer = curTime+60000;
            }
        }

        if(curTime > m_CleanupDelay)
            Cleanup();
        if(!SetThreadState(THREADSTATE_SLEEPING))
            break;
        Delay(5);
    }
    sLog.Notice("Lacrimi", "Terminating...");

    FinalCleanup();
    if(database)
        _StopDB();
    OnShutdown();
    return true;
}
//
//   FUNCTION: CServiceBase::Shutdown()
//
//   PURPOSE: The function executes when the system is shutting down. It 
//   calls the OnShutdown virtual function in which you can specify what 
//   should occur immediately prior to the system shutting down. If an error 
//   occurs, the error will be logged in the Application event log.
//
void CServiceBase::Shutdown()
{
    try
    {
        // Perform service-specific shutdown operations.
        OnShutdown();

        // Tell SCM that the service is stopped.
        SetServiceStatus(SERVICE_STOPPED);
    }
    catch (DWORD dwError)
    {
        // Log the error.
        WriteErrorLogEntry(L"Service failed to shut down.", dwError);
    }
    catch (...)
    {
        // Log the error.
        WriteEventLogEntry(L"Service failed to shut down.", TRACE_LEVEL_ERROR);
    }
}
Beispiel #18
0
	void Application::Run() {
		// Initialization
		Initialize();
		OnInitialize();

		// Main Loop
		while (!mQuit) {

			// Update simulation sub-systems.
			mGameClock.Update();
			mRenderer->Update();
			mAnimationSystem.Update();

			// Update the application.
			OnUpdate();
		}
		
		// Shutdown
		OnShutdown();
		Shutdown();
	}
Beispiel #19
0
bool LinkageWorker::Run()
{
    if (!OnInitialize()) {
        return false;
    }

    HealthTimer *health = new HealthTimer(this);
    if (!RegisterTimer(1000000000LL, health, true)) {
        delete health;
        return false;
    }

    _running_thread_id = get_current_thread_id();
    LOG(VERBOSE) << "Linkage: enter event loop [" << _running_thread_id << "]";
    bool result = true;
    while (!_quit) {
        if (!ev_run(_loop, 0)) {
            CLOG.Error("Linkage: ev_run() returned false.");
            result = false;
            break;
        }
    }
    LOG(VERBOSE) << "Linkage: leave event loop [" << _running_thread_id << "]";
    _running_thread_id = 0;

    OnShutdown();

    for (events_t::iterator p = _events.begin(); p != _events.end(); ++p) {
        DoRelease(p->second, false);
    }

    for (timers_t::iterator p = _timers.begin(); p != _timers.end(); ++p) {
        DoRelease(*p, false);
    }

    _events.clear();
    _timers.clear();
    return result;
}
	void ConnectionHandler::OnSocketReadable(const AutoPtr<ReadableNotification> &pNf) {
		// if no implementation of socket found, return
		// this is workaround for the disconnection
		if (!socket_.impl()) {
			return;
		}

		if (socket_.available() > static_cast<int>(socket_buffer_.available())) {
			socket_buffer_.resize(socket_buffer_.used() + socket_.available());
		}

		int available = socket_.available();
		// read from the socket only if there are available data
		int received_bytes = socket_.receiveBytes(socket_buffer_);
		if (received_bytes == 0 || received_bytes < available) {
			OnShutdown();
			return;
		}

		// Dispatch messages after we received bytes
		DispatchIfCan();
	}
Beispiel #21
0
//-----------------------------------------------------------------------------
// Purpose: Main loop for non-dedicated servers
//-----------------------------------------------------------------------------
int CEngineAPI::RunListenServer()
{
	//
	// NOTE: Systems set up here should depend on the mod 
	// Systems which are mod-independent should be set up in the launcher or Init()
	//

	// Innocent until proven guilty
	int nRunResult = RUN_OK;

	// Happens every time we start up and shut down a mod
	if ( ModInit( m_StartupInfo.m_pInitialMod, m_StartupInfo.m_pInitialGame ) )
	{
		CModAppSystemGroup modAppSystemGroup( false, m_StartupInfo.m_pParentAppSystemGroup );

		// Store off the app system factory...
		g_AppSystemFactory = modAppSystemGroup.GetFactory();

		nRunResult = modAppSystemGroup.Run();

		g_AppSystemFactory = NULL;

		// Shuts down the mod
		ModShutdown();

		// Disconnects from the editor window
		videomode->SetGameWindow( NULL );
	}

	// Closes down things that were set up in OnStartup
	// FIXME: OnStartup + OnShutdown should be removed + moved into the launcher
	// or the launcher code should be merged into the engine into the code in OnStartup/OnShutdown
	OnShutdown();

	return nRunResult;
}
unsigned Listener::Process()
{
	//Profile profile("Listener::Process");
    ////////////////////////////////////////
    //  handle inactive state (with UdpManager)
    if (!IsActive() && mTcpManager)
    {
		//	check all connections to see if they are idle
		std::set<Connection *>::iterator iterator;
		for (iterator = mConnections.begin(); iterator != mConnections.end(); iterator++)
		{
			Connection * connection = *iterator;
			if (connection->IsConnected())
				connection->Disconnect();
		}
		//	close the UdpManager if all the connections are closed
		if (!mConnectionCount)
		{
			mTcpManager->Release();
			mTcpManager = 0;
			OnShutdown();
		}
    }
    ////////////////////////////////////////
    //  handle active state (without UdpManager)
    else if (IsActive() && !mTcpManager)
    {
		mParams = GetConnectionParams();
        mActiveMax = GetActiveRequestMax();
        mTcpManager = new TcpManager(mParams);
		mTcpManager->SetHandler(this);
		if (mTcpManager->BindAsServer()){
            OnStartup();
        }else{
            OnFailedStartup();
            return 0;
        }
    }

    ////////////////////////////////////////
    //  process the TcpManager
    if (mTcpManager)
    {
		//Profile subProfile("TcpManager::GiveTime()");
        mTcpManager->GiveTime();
    }

	//	check all closed connections to see if they are idle
	std::list<Connection *>::iterator closedIterator = mClosedConnections.begin();
	while (closedIterator != mClosedConnections.end())
	{
		//Profile profile("Listener::Process (cleanup connection)");
		std::list<Connection *>::iterator current = closedIterator++;
		Connection * connection = *current;
		if (!connection->GetActiveRequests() && 
			!connection->GetQueuedRequests())
		{
			mClosedConnections.erase(current);
			mConnections.erase(connection);
			mConnectionCount--;
			OnConnectionDestroyed(connection);
			delete connection;
		}
	}

    ////////////////////////////////////////
    //  process request queue
    while (!mQueuedRequests.empty() && (!mActiveMax || mActiveCount < mActiveMax))
    {
		//Profile profile("Listener::Process (activate queued request)");
        QueueNode & node = mQueuedRequests.front();
        if (!IsActive())
        {
            //  If not active, discard queued request
            if (node.connection)
            {
                // normal request, internal requests have no connection
                node.connection->NotifyDiscardRequest(node.request);
            }
            DestroyRequest(node.request);
        }
        else
        {
            //  Move request to active list
            if (node.connection)
            {
                // normal request, internal requests have no connection
                node.connection->NotifyBeginRequest(node.request);
            }
            mActiveRequests.push_back(node);
			mActiveCount++;
        }
        mQueuedRequests.pop_front();
    }

    ////////////////////////////////////////
    //  Process active requests
    unsigned requestsProcessed = 0;
    std::list<QueueNode>::iterator iterator = mActiveRequests.begin();
    while (iterator != mActiveRequests.end())
    {
		//Profile profile("Listener::Process (process request)");
        std::list<QueueNode>::iterator current = iterator++;
        RequestBase * request = current->request;
        Connection * connection = current->connection;
    
        if (request->Process())
        {
            if (connection)
            {
                // normal request, internal requests have no connection
                connection->NotifyEndRequest(request);
            }
            DestroyRequest(request);
            mActiveRequests.erase(current);
			mActiveCount--;
        }
		else if (mSleepingRequests.find(request) != mSleepingRequests.end())
		{
            mActiveRequests.erase(current);
		}
	    requestsProcessed++;
    }
    return requestsProcessed;
}
//--------------------------------------------------------------------------
//	功能:向游戏发送操作
//	参数:unsigned int uDataId --> Core外部客户对core的操作请求的索引定义
//							其值为梅举类型GAMEOPERATION_INDEX的取值之一。
//		  unsigned int uParam  --> 依据uOperId的取值情况而定
//		  int nParam --> 依据uOperId的取值情况而定
//	返回:如果成功发送操作请求,函数返回非0值,否则返回0值。
//--------------------------------------------------------------------------
int	CoreServerShell::OperationRequest(unsigned int uOper, unsigned int uParam, int nParam)
{
	int nRet = 1;
	switch(uOper)
	{		
	case SSOI_BROADCASTING:
		nRet = PlayerSet.Broadcasting((char*)uParam, nParam);
		break;
	case SSOI_LAUNCH:	//启动服务
		nRet = OnLunch((LPVOID)uParam);
		break;
	case SSOI_SHUTDOWN:	//关闭服务
		nRet = OnShutdown();
		break;
	case SSOI_RELOAD_WELCOME_MSG:
		PlayerSet.ReloadWelcomeMsg();
		break;

	// relay 帮会创建成功,通知 core 进行相应的处理
	case SSOI_TONG_CREATE:
		{
			STONG_SERVER_TO_CORE_CREATE_SUCCESS	*pCreate = (STONG_SERVER_TO_CORE_CREATE_SUCCESS*)uParam;
			if (pCreate->m_nPlayerIdx <= 0 || pCreate->m_nPlayerIdx >= MAX_PLAYER)
			{
				nRet = 0;
				break;
			}
			if (Player[pCreate->m_nPlayerIdx].m_nIndex)
			{
				DWORD	dwID = g_FileName2Id(Npc[Player[pCreate->m_nPlayerIdx].m_nIndex].Name);
				if (dwID != pCreate->m_dwPlayerNameID)
				{
					nRet = 0;
					break;
				}
			}
			else
			{
				nRet = 0;
				break;
			}
			nRet = Player[pCreate->m_nPlayerIdx].CreateTong(pCreate->m_nCamp, pCreate->m_szTongName);
		}
		break;

	case SSOI_TONG_REFUSE_ADD:
		if (uParam)
		{
			STONG_SERVER_TO_CORE_REFUSE_ADD	*pRefuse = (STONG_SERVER_TO_CORE_REFUSE_ADD*)uParam;
			if (pRefuse->m_nSelfIdx > 0 && pRefuse->m_nSelfIdx <= MAX_PLAYER)
			{
				Player[pRefuse->m_nSelfIdx].m_cTong.SendRefuseMessage(pRefuse->m_nTargetIdx, pRefuse->m_dwNameID);
			}
		}
		break;

	case SSOI_TONG_ADD:
		if (uParam)
		{
			nRet = 0;
			STONG_SERVER_TO_CORE_ADD_SUCCESS	*pAdd = (STONG_SERVER_TO_CORE_ADD_SUCCESS*)uParam;
			if (pAdd->m_nPlayerIdx <= 0 || pAdd->m_nPlayerIdx >= MAX_PLAYER)
				break;
			if (Player[pAdd->m_nPlayerIdx].m_nIndex <= 0)
				break;
			if (g_FileName2Id(Npc[Player[pAdd->m_nPlayerIdx].m_nIndex].Name) != pAdd->m_dwPlayerNameID)
				break;
			Player[pAdd->m_nPlayerIdx].m_cTong.AddTong(
				pAdd->m_nCamp,
				pAdd->m_szTongName,
				pAdd->m_szMasterName,
				pAdd->m_szTitleName);
		}
		break;

	default:
		nRet = 0;
		break;
	}	
	return nRet;
}
Beispiel #24
0
int main(int ac, char **av, char **envp)
{
	BinaryDir = GetFullProgDir(av[0]);
	if (BinaryDir[BinaryDir.length() - 1] == '.')
		BinaryDir = BinaryDir.substr(0, BinaryDir.length() - 2);

#ifdef _WIN32
	Anope::string::size_type n = BinaryDir.rfind('\\');
#else
	Anope::string::size_type n = BinaryDir.rfind('/');
#endif
	Anope::ServicesDir = BinaryDir.substr(0, n);

#ifdef _WIN32
	/* Clean out the module runtime directory prior to running, just in case files were left behind during a previous run */
	ModuleManager::CleanupRuntimeDirectory();

	OnStartup();
#endif

	try
	{
		/* General initialization first */
		Anope::Init(ac, av);
	}
	catch (const CoreException &ex)
	{
		Anope::Logger.Log(ex.GetReason());
		return -1;
	}

	try
	{
		Uplink::Connect();
	}
	catch (const SocketException &ex)
	{
		Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason());
	}

	/* Set up timers */
	time_t last_check = Anope::CurTime;
	ExpireTimer expireTimer(Config->GetBlock("options")->Get<time_t>("expiretimeout", "30m"));
	Uplink::PingTimer pingTimer(30);

	/*** Main loop. ***/
	while (!Anope::Quitting)
	{
		Anope::Logger.Debug2("Top of main loop");

		/* Process timers */
		if (Anope::CurTime - last_check >= Config->TimeoutCheck)
		{
			TimerManager::TickTimers(Anope::CurTime);
			last_check = Anope::CurTime;
		}

		/* Process the socket engine */
		SocketEngine::Process();

		if (Anope::Signal)
			Anope::HandleSignal();
	}

	if (Anope::Restarting)
	{
		EventManager::Get()->Dispatch(&Event::Restart::OnRestart);
	}
	else
	{
		EventManager::Get()->Dispatch(&Event::Shutdown::OnShutdown);
	}

	if (Anope::QuitReason.empty())
		Anope::QuitReason = "Terminating, reason unknown";
	Anope::Logger.Log(Anope::QuitReason);

	delete UplinkSock;

	ModuleManager::UnloadAll();
	SocketEngine::Shutdown();
	for (Module *m; (m = ModuleManager::FindFirstOf(PROTOCOL)) != NULL;)
		ModuleManager::UnloadModule(m, NULL);

#ifdef _WIN32
	ModuleManager::CleanupRuntimeDirectory();

	OnShutdown();
#endif

	if (Anope::Restarting)
	{
		chdir(BinaryDir.c_str());
		Anope::string sbin = "./" + Anope::ServicesBin;
		av[0] = const_cast<char *>(sbin.c_str());
		execve(Anope::ServicesBin.c_str(), av, envp);
		Anope::Logger.Log("Restart failed");
		Anope::ReturnValue = -1;
	}

	return Anope::ReturnValue;
}
Beispiel #25
0
//============================================================
// <T>服务器关闭处理。</T>
//
// @return 处理结果
//============================================================
TResult FServer::Shutdown(){
   MO_INFO("Server '%s' shutdown.", (TCharC*)_name);
   _stop = ETrue;
   return OnShutdown();
}
Beispiel #26
0
void xConsoleApplication::Shutdown()
{
    OnShutdown();
}
	void ConnectionHandler::OnSocketShutdown(const AutoPtr<ShutdownNotification> &pNf) {
		socket_down_ = true;

		OnShutdown();
	}