예제 #1
0
/********************************
Start
    Starts up the SMTP server class
    Connects to port 25 and starts
    listening for connections
Params
    none
Return
    UTE_SUCCESS         - success
    UTE_CONNECT_FAILED  - connect to port 25 failed
    UTE_ACCEPT_FAILED   - start accepting failed
*********************************/
int CUT_SMTPServer::Start(){

    if(ConnectToPort(m_nPort) != UTE_SUCCESS)
        return m_ptrMailServer->OnError(UTE_CONNECT_FAILED);
    if(StartAccept() != UTE_SUCCESS)
        return m_ptrMailServer->OnError(UTE_ACCEPT_FAILED);
    return m_ptrMailServer->OnError(UTE_SUCCESS);
}
예제 #2
0
CLineServer::CLineServer( boost::asio::io_service & p_service,
    unsigned short p_port, TSetCallback p_set, TGetCallback p_get )
    : m_acceptor(p_service), m_socket(p_service), m_set(p_set), m_get(p_get)
{
    boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::tcp::v4(), p_port );
    
    // open the acceptor at the endpoint
    m_acceptor.open( endpoint.protocol() );
    m_acceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address(true) );
    m_acceptor.bind( endpoint );
    m_acceptor.listen();
    
    // wait for connections
    StartAccept();
}
예제 #3
0
void CJsAsioAccept::handle_accept( boost::shared_ptr<CJsAsioSession> new_connect, const boost::system::error_code& error )
{
	if (!error)
	{
		new_connect->StartSession( _session );
	}
	else
	{
		LOGE(error.message());
		//std::cout<<"error accept >>"<<error.message()<<std::endl;
		return;
	}

	StartAccept();
}
예제 #4
0
   void
   TCPServer::Run()
   {
      if (connection_security_ == CSSSL ||
          connection_security_ == CSSTARTTLSOptional ||
          connection_security_ == CSSTARTTLSRequired)
      {
         if (!InitSSL())
            return;
      }

      if (!InitAcceptor())
         return;

      StartAccept();
   }
예제 #5
0
BOOL CTcpServer::Start(LPCTSTR pszBindAddress, USHORT usPort)
{
	if(!CheckParams() || !CheckStarting())
		return FALSE;

	if(CreateListenSocket(pszBindAddress, usPort))
		if(CreateCompletePort())
			if(CreateWorkerThreads())
				if(StartAccept())
				{
					m_enState = SS_STARTED;
					return TRUE;
				}

	Stop();

	return FALSE;
}
예제 #6
0
 EchoServer(std::string const& locAddr, std::string const& port, unsigned threadsCount)
   : Acceptor(IoService)
   , Threads(threadsCount)
 {
   boost::asio::ip::tcp::resolver Resolver(IoService);
   boost::asio::ip::tcp::resolver::query Query(locAddr, port);
   boost::asio::ip::tcp::endpoint Endpoint = *Resolver.resolve(Query);
   Acceptor.open(Endpoint.protocol());
   Acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
   Acceptor.bind(Endpoint);
   Acceptor.listen();
   
   StartAccept();
   
   std::generate(Threads.begin(), Threads.end(),
                 boost::bind(
                   &boost::make_shared<boost::thread, boost::function<void ()> const &>,
                   boost::function<void ()>(boost::bind(&boost::asio::io_service::run, &IoService))
                   ));
 }
예제 #7
0
BOOL CTcpServer::Start(LPCTSTR lpszBindAddress, USHORT usPort)
{
	if(!CheckParams() || !CheckStarting())
		return FALSE;

	PrepareStart();

	if(CreateListenSocket(lpszBindAddress, usPort))
		if(CreateCompletePort())
			if(CreateWorkerThreads())
				if(StartAccept())
				{
					m_enState = SS_STARTED;
					return TRUE;
				}

	DWORD dwCode = ::GetLastError();

	Stop();

	::SetLastError(dwCode);

	return FALSE;
}
예제 #8
0
CJsAsioAccept::CJsAsioAccept( boost::asio::io_service& io_service, boost::shared_ptr<CJsAsioSessionGroup> session, UINT16 port )
	: _session(session),
	_acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
{
	StartAccept();
}
예제 #9
0
   void 
   TCPServer::HandleAccept(shared_ptr<TCPConnection> pConnection,
      const boost::system::error_code& error)
   {
      if (error.value() == 995)
      {
         String sMessage;
         sMessage.Format(_T("TCP - AcceptEx failed. Error code: %d, Message: %s"), error.value(), String(error.message()));
         LOG_DEBUG(sMessage);

         /*
             995: The I/O operation has been aborted because of either a thread exit or an application request
             
             This happens when the servers are stopped. We shouldn't post any new accepts or do anything
             else in this situation.
        */

         return;
      }

      // Post another AcceptEx. We should always have outstanding unless the 
      // server is stopping, which we are taking care of above.
      StartAccept();

      if (!error)
      {
         boost::asio::ip::tcp::endpoint localEndpoint = pConnection->GetSocket().local_endpoint();
         boost::asio::ip::tcp::endpoint remoteEndpoint = pConnection->GetSocket().remote_endpoint();

         IPAddress localAddress (localEndpoint.address());
         IPAddress remoteAddress (remoteEndpoint.address());

         String sMessage = Formatter::Format("TCP - {0} connected to {1}:{2}.", remoteAddress.ToString(), localAddress.ToString(), port_);
         LOG_TCPIP(sMessage);

         shared_ptr<SecurityRange> securityRange = PersistentSecurityRange::ReadMatchingIP(remoteAddress);

         if (!securityRange)
         {
            LOG_TCPIP("TCP - Connection dropped - No matching IP range.");
            return;
         }


         bool allow = SessionManager::Instance()->GetAllow(sessionType_, securityRange);
        
         if (!allow)
         {
            // Session creation failed. May not be matching IP range, or enough connections have been created.
            String message;
            message.Format(_T("Client connection from %s was not accepted. Blocked either by IP range or by connection limit."), String(remoteAddress.ToString()));
            LOG_DEBUG(message);

            // Give option to hold connection for anti-pounding & hopefully minimize DoS
            // NOTE: We really need max connections per IP as well
            int iBlockedIPHoldSeconds = IniFileSettings::Instance()->GetBlockedIPHoldSeconds();

            if (iBlockedIPHoldSeconds > 0)
            {
               Sleep(iBlockedIPHoldSeconds * 1000);
               message.Format(_T("Held connection from %s for %i seconds before dropping."), String(remoteAddress.ToString()), iBlockedIPHoldSeconds);
               LOG_DEBUG(message);
            }

            return;
         }

         if (!FireOnAcceptEvent(remoteAddress, localEndpoint.port()))
            return;

         pConnection->SetSecurityRange(securityRange);
         pConnection->Start();
      }
      else
      {
         if (error.value() == 10009 || error.value() == 995)
         {
            // Not really errors..
            return;
         }

         // The outstanding accept-ex failed. This may or may not be an error. Default to being positive.
         String sMessage;
         sMessage.Format(_T("TCP - AcceptEx failed. Error code: %d, Message: %s"), error.value(), String(error.message()));
         LOG_TCPIP(sMessage);
      }
   }
예제 #10
0
void APIServerListener::HandleAccept(std::tr1::shared_ptr<APIServerConnection> connection)
{
	connection->Process();
	StartAccept();
}
예제 #11
0
APIServerListener::APIServerListener(asio::io_service& io)
{
    _acceptor = new asio::ip::tcp::acceptor(io, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), sConfig.net.apiServerPort));
    sLog.Log("api server", "listening on port %i", (sConfig.net.apiServerPort));
	StartAccept();
}
예제 #12
0
 void HandleAccept(boost::system::error_code const &error)
 {
   if (!error)
     NewConnection->Start();
   StartAccept();
 }
ImageServerListener::ImageServerListener(asio::io_service& io)
{
	_acceptor = new asio::ip::tcp::acceptor(io, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), sConfig.net.port + 1));
	sLog.Log("image server", "listening on port %i", (sConfig.net.port + 1));
	StartAccept();
}
예제 #14
0
BOOL CGame::Init()
{
	// 创建日志保存目录
	CreateDirectory("log", NULL);

//#ifdef _RUNSTACKINFO_
//	InitStackFileName();
//#endif

	srand((unsigned)time(NULL));
	random(100);
	PutDebugString("Server start!!!");

	// 装载资源
	LoadServerResource();

	if(!LoadSetup())
	{
		return FALSE;
	}

	// 加载GameServer配置
	if(!LoadGSSetup("GSSetup.ini"))
	{
		return FALSE;
	}

	// 初始化CMyAdoBase
	CMyAdoBase::Initialize(m_tgSetup.strSqlConType, m_tgSetup.strSqlServerIP, m_tgSetup.strDBName,
		m_tgSetup.strSqlUserName, m_tgSetup.strSqlPassWord);


	m_pRsBouns = new CRsBouns();

	if(m_pRsBouns->LoadBounsDes(m_mapBounsDes) == S_OK )
	{
		AddLogText("加载奖励资源表成功!");
	}
	else
	{
		MessageBox(g_hWnd, "Load Bouns Failed!", "Message", MB_OK);
		return FALSE;
	}

	// 分配数据块
	m_pDBAllocator = new CDataBlockAllocator(m_tgSetup.dwDataBlockNum, m_tgSetup.dwDataBlockSize);

	GetGame()->GetBounsDBManager()->InitOperThread(m_tgSetup.strSqlConType, m_tgSetup.strSqlServerIP, m_tgSetup.strDBName,
		m_tgSetup.strSqlUserName, m_tgSetup.strSqlPassWord);

	CMessage::Initial(m_pDBAllocator, m_tgSetup.dwFreeMsgNum);
	// 初始化服务器网络
	CMySocket::MySocketInit();

	// 装载内存影射文件配置
	//LoadMapFileSetup();

	// 创建服务器端
	if( !InitNetServer() )
	{
		MessageBox(g_hWnd, "Initial NetServer failed!", "Message", MB_OK);
		return FALSE;
	}

	// 开始监听
	if( !StartAccept() )
	{
		return FALSE;
	}

	//// 日志服务器
	//if( m_tgSetup.lUseLogServer == 0 )
	//{
	//	AddLogText("连接LogServer配置为不连接,日志服务将不能使用!");
	//}
	//else
	//{
	//	if( !StartConnectLogServer() )
	//	{
	//		AddLogText("Connect LogServer Failed!");
	//		CreateConnectLogThread();
	//	}
	//	else
	//	{
	//		AddLogText("Connect LogServer Successfully!");
	//	}
	//}

	return TRUE;
}