Esempio n. 1
0
int main(int argc, char* argv[])
{
	if (argc != 2)
	{
		std::cout << "USAGE: <Interfaces|Callbacks>" << std::endl;
		return EXIT_SUCCESS;
	}

	auto c = std::make_shared<int>(3);
	const int ciclesB = 1000000 * 5;
	const int ciclesC = 1000000 * 5;

	if (std::string("interfaces") == argv[1])
	{
		auto listener = std::make_shared<ConcreteListener>();
		auto generator = std::make_shared<AsyncGenerator>(listener);

		Timer.start();

		for (int i = 0; i < ciclesB; ++i)
		{
			generator->makeB(1);
		}
		for (int i = 0; i < ciclesC; ++i)
		{
			generator->makeC(c);
		}
		generator->makeB(0);

		Mutex.lock();
	}
	else if (std::string("callbacks") == argv[1])
	{
		auto generator = std::make_shared<CallbackGenerator>(ReceiverB, ReceiverC);

		Timer.start();

		for (int i = 0; i < ciclesB; ++i)
		{
			generator->makeB(1);
		}
		for (int i = 0; i < ciclesC; ++i)
		{
			generator->makeC(c);
		}
		generator->makeB(0);

		Mutex.lock();
	}

	std::cout << "ElapsedTime: " << boost::timer::format(ElapsedTime) << std::endl;
	std::cin.get();
	return EXIT_SUCCESS;
}
void cia_client::start()
{
	m_started_ = true;
	clients.push_back(shared_from_this());
	m_update_time.start();
	do_read_header();
	if (m_timeout_elapsed != 0)
	{
		do_timeout_check();
	}
	BOOST_LOG_SEV(cia_g_logger, Debug) << "新的客户端socket已经运行";
}
inline void cia_client::do_deal_request(boost::shared_ptr<chat_message> ch_msg)
{
	if (!ch_msg->parse_cia_mag()) {
		BOOST_LOG_SEV(cia_g_logger, Debug) << "报文转换失败, 本次请求不做处理";
		//m_chat_msg_queue.Put(ch_msg);
		return;
	}	
	if (ch_msg->m_procbuffer_msg.type() == CIA_LOGIN_REQUEST){
		BOOST_LOG_SEV(cia_g_logger, Debug) << "本次请求判断为登陆请求";
		do_deal_login_request(ch_msg);
	}
	else if (ch_msg->m_procbuffer_msg.type() == CIA_HEART_RESPONSE){
		//m_chat_msg_queue.Put(ch_msg);
		BOOST_LOG_SEV(cia_g_logger, AllEvent) << "本次请求判断为心跳回应, 已对客户端的最后连接时间做更新";
		m_update_time.start();
	}
	else if (ch_msg->m_procbuffer_msg.type() == CIA_CALL_REQUEST){
		//BOOST_LOG_SEV(cia_g_logger, Debug) << "本次请求判断为呼叫请求";
		do_deal_call_out_request(ch_msg);
	}
}
inline void cia_client::do_read_body(boost::shared_ptr<chat_message> ch_msg_)
{
	ptr self = shared_from_this();
	//BOOST_LOG_SEV(cia_g_logger, Debug) << "开始准备异步读取数据";	
	boost::asio::async_read(m_sock_,
		boost::asio::buffer(ch_msg_->body(), ch_msg_->body_length()),
		[this, self, ch_msg_](boost::system::error_code ec, std::size_t /*length*/)
	{
		if (!ec)
		{
			//BOOST_LOG_SEV(cia_g_logger, Debug) << "已读取新的消息体, 开始进行下一次读取";
			do_read_header();
			m_update_time.start();
			//BOOST_LOG_SEV(cia_g_logger, Debug) << "开始解析本次请求的消息体";
			do_deal_request(ch_msg_);
		}
		else
		{
			BOOST_LOG_SEV(cia_g_logger, Debug) << "接收新的数据出错, 已经关闭此socket, 错误码:" << ec;
			stop();
		}
	});
}
Esempio n. 5
0
	/**
	* 每次呼叫完毕, 需要重置相关资源
	*
	*/
	void realseTrunk()
	{
		m_step = TRK_IDLE;
		m_callTime.start();
		m_call_out_param.reset();
	}
Esempio n. 6
0
	void reset_trunk(boost::shared_ptr<cti_call_out_param> call_out_param_)
	{
		m_step = TRK_WAIT_CONNECT;
		m_call_out_param = call_out_param_;
		m_callTime.start();
	}