예제 #1
0
/**
 *  Nachrichtenschleife.
 *
 *  @author FloSoft
 */
int LobbyServer::Run(void)
{
    // Clients testen (auf timeout usw)
    if(!CheckClientTimeouts())
        return 2;

    // neue Clients verbinden
    if(!CheckForNewClients())
        return 3;

    // Daten weiterleiten
    if(!ProcessMessages())
        return 4;

    // ggf. stoppen
    if(stop == true)
        return 100;

#ifdef _WIN32
    Sleep(20);
#else
    usleep(20);
#endif

    return 0;
}
예제 #2
0
XnStatus XnSensorServer::ServerMainLoop()
{
	for (;;)
	{
		CheckForNewClients(XN_SENSOR_SERVER_ACCEPT_CONNECTION_TIMEOUT);

		// do some clean-up
		m_sensorsManager.CleanUp();
		CleanUpSessions();

		// now check if we should shutdown
		if (ShutdownIfPossible())
		{
			break;
		}
	}

	return XN_STATUS_OK;
}
예제 #3
0
XnBool XnSensorServer::ShutdownIfPossible()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// lock sessions list
	XnAutoCSLocker locker(m_hSessionsLock);

	// check if no sessions and no sensors
	if (CanShutdown())
	{
		// lock the running lock
		XnAutoMutexLocker serverRunningLock(m_hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_TIMEOUT);
		nRetVal = serverRunningLock.GetStatus();
		if (nRetVal == XN_STATUS_OK)
		{
			// make sure no client is waiting to connect
			CheckForNewClients(0);

			// re-check shutdown condition
			if (CanShutdown())
			{
				xnLogInfo(XN_MASK_SENSOR_SERVER, "No sensors are open and no client is connected. Shutting down...");

				// reset the event (to notify server is no longer up)
				nRetVal = xnOSResetEvent(m_hServerRunningEvent);
				if (nRetVal != XN_STATUS_OK)
				{
					xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to reset sensor server event: %s - proceeding with shutdown.", xnGetStatusString(nRetVal));
					XN_ASSERT(FALSE);
				}

				// and close the socket (to free the port for another server)
				xnOSCloseSocket(m_hListenSocket);
				m_hListenSocket = NULL;

				return TRUE;
			}
		}
	}

	return FALSE;
}