Exemple #1
0
    Wall::Wall() {

        QSharedPointer< point3D<double> > spoint(new point3D<double>());
        startPoint = spoint;
        QSharedPointer< point3D<double> > epoint(new point3D<double>());
        endPoint = epoint;
    }
bool zTCPServer::bind(const char *pstrIP, uint16_t usPort, zNetService* pService)
{	
	//m_pAcceptor_ = new asio::ip::tcp::acceptor(m_ioServicePool_.get_io_service());
	m_pAcceptor_ = new asio::ip::tcp::acceptor(m_ioServicePool_.get_first_service());
	asio::ip::tcp::endpoint epoint(asio::ip::address::from_string(pstrIP),usPort);
	m_pAcceptor_->open(epoint.protocol());
	m_pAcceptor_->set_option(asio::ip::tcp::acceptor::reuse_address(true));
	m_pAcceptor_->bind(epoint);

	m_pAcceptor_->listen();

	//m_pCheckTimer = new asio::deadline_timer(m_ioServicePool_.get_first_service());
	//m_pCheckTimer.expires_from_now(boost::posix_time::seconds(CHECK_TASK_INTER));
	//m_pCheckTimer.async_wait(boost::bind(&zSocket::Check,this,asio::placeholders::error));

	m_usPort = usPort;
	m_strIP = pstrIP;
	//zTCPTask_Ptr pNewSession(new zTCPTask(m_ioServicePool_.get_io_service()));
	//zTCPTask_Ptr pNewSession(CreateTask(usPort));
	for (int i = 0; i < 10; ++i)  //投递10个
	{
		//zTCPTask * pNewSession = CreateTask(usPort);
		zTCPTask * pNewSession = pService->newTCPTask(m_usPort);
		m_pAcceptor_->async_accept(pNewSession->socket(),
			boost::bind(&zTCPServer::handle_accept,this,pNewSession,pService,asio::placeholders::error));
		AddTask(pNewSession);
	}

	return true;
}