Exemplo n.º 1
0
void ServicePort::open(IPAddressList ips, uint16_t port)
{
  m_serverPort = port;
  m_pendingStart = false;

  for(IPAddressList::iterator ip = ips.begin(); ip != ips.end(); ++ip){
    try{
      // std::cout << "\n" << ip->to_string() << "\n";
      Acceptor_ptr aptr(new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(*ip, m_serverPort)));

      aptr->set_option(boost::asio::ip::tcp::no_delay(true));

      accept(aptr);
      m_tcp_acceptors.push_back(aptr);
    }
    catch(boost::system::system_error& e){
      if(m_logError){
        LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what());
        m_logError = false;
      }

      m_pendingStart = true;
      g_scheduler.addEvent(createSchedulerTask(5000,
        boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), *ip, port)));
    }
  }
}
Exemplo n.º 2
0
void ServicePort::service(boost::weak_ptr<ServicePort> weakService, IPAddress ip, uint16_t port)
{
	if(weakService.expired())
		return;

	ServicePort_ptr service = weakService.lock();
	if(!service)
		return;

	IPAddressList ips;
	ips.push_back(ip);
	service->open(ips, port);
}
Exemplo n.º 3
0
void ServicePort::openAcceptor(boost::weak_ptr<ServicePort> weak_service, IPAddress ip, uint16_t port)
{
  if(weak_service.expired()){
    return;
  }

  if(ServicePort_ptr service = weak_service.lock()){
    #ifdef __DEBUG_NET_DETAIL__
    std::cout << "ServicePort::openAcceptor" << std::endl;
    #endif
    IPAddressList ips;
    ips.push_back(ip);
    service->open(ips, port);
  }
}
Exemplo n.º 4
0
void ServicePort::open(IPAddressList ips, uint16_t port)
{
	m_pendingStart = false;
	m_serverPort = port;

	bool error = false;
	IPAddressList pendingIps;
	for(IPAddressList::iterator it = ips.begin(); it != ips.end(); ++it)
	{
		try
		{
			Acceptor_ptr tmp(new boost::asio::ip::tcp::acceptor(m_io_service,
				boost::asio::ip::tcp::endpoint(*it, m_serverPort)));
			tmp->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
			tmp->set_option(boost::asio::ip::tcp::no_delay(true));

			accept(tmp);
			m_acceptors[tmp] = *it;
		}
		catch(std::exception& e)
		{
			if(m_logError)
			{
				LOG_MESSAGE(LOGTYPE_ERROR, e.what(), "NETWORK")
				pendingIps.push_back(*it);
				if(!error)
					error = true;
			}
		}
	}

	if(error)
	{
		m_logError = false;
		m_pendingStart = true;
		Scheduler::getInstance().addEvent(createSchedulerTask(5000, boost::bind(
			&ServicePort::services, boost::weak_ptr<ServicePort>(shared_from_this()), pendingIps, m_serverPort)));
	}
}
Exemplo n.º 5
0
void SessionServer::OnStart(DWORD dwArgc, PWSTR *pszArgv)
{
    InitializeFileLogger();

    // Log out an obvious piece of text to help distinguish between server sessions.
    LogInfo("***********************************");
    LogInfo("****** Sharing Service OnStart ******");
    LogInfo("***********************************");

	// Log a service start message to the Application log.
	WriteEventLogEntry(L"Sharing Server starting", EVENTLOG_INFORMATION_TYPE);
	LogInfo("Server Info: \n\tBuild Version: %ls \n\tSchema Version: %i", XTOOLS_VERSION_STRING, kXToolsSchemaVersion);

	// TODO: use different machines, etc, based on command line parameters
	XT_UNREFERENCED_PARAM(dwArgc);
	XT_UNREFERENCED_PARAM(pszArgv);

	// Start listening for new connections
	m_listenerReceipt = m_socketMgr->AcceptConnections(kSessionServerPort, kSessionServerMaxConnections, this);
	LogInfo("Listening for session list connections on port %i of all network devices of the local machine.", kSessionServerPort);
	LogInfo("Local IP addresses are:");

	IPAddressList addressList = m_socketMgr->GetLocalMachineAddresses();
	for (size_t i = 0; i < addressList.size(); ++i)
	{
		LogInfo("\t%s", addressList[i].ToString().c_str());
	}
	
	// Allocate a pool of ports to use for sessions
	m_portPool = new PortPool(kSessionServerPort-1, 256);

	// TODO: Read from a configuration file for persistent sessions. 
	XTVERIFY(CreateNewSession("Default", SessionType::PERSISTENT) != NULL);

	// Start a thread to run the main service logic. 
	m_serverThread = new MemberFuncThread(&SessionServer::ServerThreadFunc, this);
}