void ListenerSocketConnection::readMessages() {
	String key = getInstance();

	try {
		continueRead = true;
		while( continueRead )
			performRead();
	}
	catch ( RuntimeException& e ) {
		logger.logError( "readMessages: connection=" + key + " - exception caught:" );
		logger.printStack( e );
	}
	catch ( ... ) {
		logger.printStack();
		logger.logError( "readMessages: connection=" + key + " - unknown exception in read" );
	}

	try {
		stopConnection();
	}
	catch ( ... ) {
		logger.printStack();
		logger.logError( "readMessages: connection=" + key + " - unknown exception in stop" );
	}
}
Beispiel #2
0
bool ServerManager::linkTcp(EncTcpStartPoint& tcp) {
    std::cout << "link avant verification " << std::endl;
    if(connection == 0)
        while(!stopConnection()){}
    std::cout << "link apres verification " << std::endl;
    connection = &tcp;
    return true;
}
VOID SvcInit(DWORD dwArgc, LPTSTR *lpszArgv)
{
	// TO_DO: Declare and set any required variables.
	//   Be sure to periodically call ReportSvcStatus() with 
	//   SERVICE_START_PENDING. If initialization fails, call
	//   ReportSvcStatus with SERVICE_STOPPED.

	// Create an event. The control handler function, SvcCtrlHandler,
	// signals this event when it receives the stop control code.

	ghSvcStopEvent = CreateEvent(
		NULL,    // default security attributes
		TRUE,    // manual reset event
		FALSE,   // not signaled
		NULL);   // no name

	if (ghSvcStopEvent == NULL)
	{
		ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
		
		return;
	}

	// Report running status when initialization is complete.

		ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
	// TO_DO: Perform work until service stops.
    // Check whether to stop the service.
	
		int Data_Of_Thread_1 = 1;
		HANDLE Handle_Of_Thread_1 = 0;
		Handle_Of_Thread_1 = CreateThread(NULL, 0,
			server , NULL, 0, NULL);
		if (Handle_Of_Thread_1 == NULL)
			ExitProcess(Data_Of_Thread_1);


		while (1)
		{
			// Check whether to stop the service.

			WaitForSingleObject(ghSvcStopEvent, INFINITE);
			stopConnection();
			WaitForSingleObject(Handle_Of_Thread_1, 0);
			CloseHandle(Handle_Of_Thread_1);
			ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
			return;
		}
	
}
Beispiel #4
0
void CClient::endGame( bool closeConnection /*= true*/ )
{
	//suggest interfaces to finish their stuff (AI should interrupt any bg working threads)
	for(auto i : playerint)
		i.second->finish();

	// Game is ending
	// Tell the network thread to reach a stable state
	if(closeConnection)
		stopConnection();
    logNetwork->infoStream() << "Closed connection.";

	GH.curInt = nullptr;
	{
		boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
		logNetwork->infoStream() << "Ending current game!";
		if(GH.topInt())
		{
			GH.topInt()->deactivate();
		}
		GH.listInt.clear();
		GH.objsToBlit.clear();
		GH.statusbar = nullptr;
		logNetwork->infoStream() << "Removed GUI.";

		vstd::clear_pointer(const_cast<CGameInfo*>(CGI)->mh);
		vstd::clear_pointer(gs);

		logNetwork->infoStream() << "Deleted mapHandler and gameState.";
		LOCPLINT = nullptr;
	}

	playerint.clear();
	battleints.clear();
	callbacks.clear();
	battleCallbacks.clear();
	CGObelisk::reset();
	logNetwork->infoStream() << "Deleted playerInts.";
	logNetwork->infoStream() << "Client stopped.";
}