void Master::doHeartbeat(const boost::system::error_code& e) { // Cancelled? if (e) { return; } std::lock_guard<std::recursive_mutex> hLock(heartbeatMutex); if (!heartbeatRunning) return; // Do heartbeat { std::lock_guard<std::recursive_mutex> lock(listenersMutex); for (auto *l: listeners) l->heartbeat(*this); } // Setup next heartbeat heartbeatTimer.expires_from_now(boost::posix_time::seconds(3)); heartbeatTimer.async_wait([this] (const boost::system::error_code& e){ doHeartbeat(e); }); }
void FServerConsole::Serialize( const TCHAR* sData, ELogVerbosity::Type eVerbosity, const class FName& sCategory, const double fTime ) { FScopeLock hLock( &m_hLock ); #if PLATFORM_WINDOWS COORD hCursorPosition = GetCursorPosition(); #endif ClearInputLine(); m_pConsole->Serialize( sData, eVerbosity, sCategory, fTime ); RedrawInputLine(); #if PLATFORM_WINDOWS hCursorPosition.Y = GetCursorPosition().Y; SetCursorPosition( hCursorPosition ); #endif }
void Master::invalidate() { // Already invalidated? if (disposed) { return; } BOOST_LOG_SEV(log, LogLevel::Info) << "Master server is going DOWN."; disposed = true; { std::lock_guard<std::recursive_mutex> hLock(heartbeatMutex); heartbeatRunning = false; heartbeatTimer.cancel(); } nodeAcceptor.cancel(); clientAcceptor.cancel(); // Wait until node/client acceptor is closed { std::unique_lock<std::mutex> acceptorLock(nodeAcceptorMutex); nodeAcceptorCV.wait(acceptorLock, [&]{ return !nodeAcceptorRunning; }); } { std::unique_lock<std::mutex> acceptorLock(clientAcceptorMutex); clientAcceptorCV.wait(acceptorLock, [&]{ return !clientAcceptorRunning; }); } // Delete node/client acceptor waitingNodeConnection->shutdown(); waitingNodeConnection.reset(); waitingClient->shutdown(); waitingClient.reset(); nodeAcceptor.close(); clientAcceptor.close(); // Reject all pending clients std::vector<PendingClient> pclientList; { std::lock_guard<std::recursive_mutex> lock(pendingClientsMutex); for (const auto& e: pendingClients) pclientList.push_back(e.second); } for (const auto& c: pclientList) c.response->reject("Server is going down."); // Shut all clients down std::vector<std::shared_ptr<MasterClient>> clientList; { std::lock_guard<std::recursive_mutex> lock(clientsMutex); for (const auto& e: clients) clientList.push_back(e.second); } for (const auto& c: clientList) c->shutdown(); // Shut all connections down std::vector<std::shared_ptr<MasterNodeConnection>> nodeConns; { std::lock_guard<std::recursive_mutex> lock(nodeConnectionsMutex); std::copy(nodeConnections.begin(), nodeConnections.end(), std::back_inserter(nodeConns)); } for (const auto& c: nodeConns) c->shutdown(); _library = nullptr; }