Esempio n. 1
0
void 
CServerApp::handleClientConnected(const CEvent&, void* vlistener)
{
	CClientListener* listener = reinterpret_cast<CClientListener*>(vlistener);
	CClientProxy* client = listener->getNextClient();
	if (client != NULL) {
		s_server->adoptClient(client);
		updateStatus();
	}
}
Esempio n. 2
0
void 
NetworkTests::sendToClient_mockFile_handleClientConnected(const CEvent&, void* vlistener)
{
	CClientListener* listener = reinterpret_cast<CClientListener*>(vlistener);
	CServer* server = listener->getServer();

	CClientProxy* client = listener->getNextClient();
	if (client == NULL) {
		throw runtime_error("client is null");
	}

	CBaseClientProxy* bcp = reinterpret_cast<CBaseClientProxy*>(client);
	server->adoptClient(bcp);
	server->setActive(bcp);

	server->sendFileToClient(kMockFilename);
}
Esempio n. 3
0
void 
CServerApp::handleClientConnected(const CEvent&, void* vlistener)
{
	CClientListener* listener = reinterpret_cast<CClientListener*>(vlistener);
	CClientProxy* client = listener->getNextClient();
	if (client != NULL) {
		s_server->adoptClient(client);
		updateStatus();

		if (args().m_enableVnc) {
			// TODO: figure out client IP address from name.
			CVncClient* vncClient = new CVncClient("192.168.0.13", client->getName());
			vncClient->start();
			m_vncClients.insert(std::pair<CString, CVncClient*>(client->getName(), vncClient));
		}
	}
}
Esempio n. 4
0
bool 
CServerApp::startServer()
{
	// skip if already started or starting
	if (m_serverState == kStarting || m_serverState == kStarted) {
		return true;
	}

	// initialize if necessary
	if (m_serverState != kInitialized) {
		if (!initServer()) {
			// hard initialization failure
			return false;
		}
		if (m_serverState == kInitializing) {
			// not ready to start
			m_serverState = kInitializingToStart;
			return true;
		}
		assert(m_serverState == kInitialized);
	}

	double retryTime;
	CClientListener* listener = NULL;
	try {
		listener   = openClientListener(args().m_config->getSynergyAddress());
		m_server   = openServer(*args().m_config, m_primaryClient);
		listener->setServer(m_server);
		m_listener = listener;
		updateStatus();
		LOG((CLOG_NOTE "started server, waiting for clients"));
		m_serverState = kStarted;
		return true;
	}
	catch (XSocketAddressInUse& e) {
		LOG((CLOG_WARN "cannot listen for clients: %s", e.what()));
		closeClientListener(listener);
		updateStatus(CString("cannot listen for clients: ") + e.what());
		retryTime = 10.0;
	}
	catch (XBase& e) {
		LOG((CLOG_CRIT "failed to start server: %s", e.what()));
		closeClientListener(listener);
		return false;
	}

	if (args().m_restartable) {
		// install a timer and handler to retry later
		assert(m_timer == NULL);
		LOG((CLOG_DEBUG "retry in %.0f seconds", retryTime));
		m_timer = m_events->newOneShotTimer(retryTime, NULL);
		m_events->adoptHandler(CEvent::kTimer, m_timer,
			new TMethodEventJob<CServerApp>(this, &CServerApp::retryHandler));
		m_serverState = kStarting;
		return true;
	}
	else {
		// don't try again
		return false;
	}
}