Пример #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::do_timeout_check()
{
	if (m_started_)
	{
		m_check_timeout_timer.expires_from_now(boost::posix_time::milliseconds(TIMEOUT_CHECK_ELAPSED));
		ptr self = shared_from_this();
		//BOOST_LOG_SEV(cia_g_logger, AllEvent) << "开始准备异步检测超时, 触发检测的时间是在"
		//	<< TIMEOUT_CHECK_ELAPSED << "毫秒后, " << "客户端socket超时时间设置为" << m_timeout_elapsed << "毫秒";
		m_check_timeout_timer.async_wait([this, self](const error_code& ec){
			if (ec)
			{
				BOOST_LOG_SEV(cia_g_logger, Debug) << "已停止超时检测";
				stop();
				return;
			}
			std::size_t elapsed_time_ = std::size_t(m_update_time.elapsed().wall / 1000000);
			if (elapsed_time_ > m_timeout_elapsed) {
				BOOST_LOG_SEV(cia_g_logger, Debug) << "客户端因超时关闭, 已经在"
					<< elapsed_time_ << "毫秒内无任何动作";
				stop();
			}
			else if (elapsed_time_ > m_timeout_elapsed / 2) {
				BOOST_LOG_SEV(cia_g_logger, AllEvent) << "向客户端发送心跳请求, 已经在"
					<< elapsed_time_ << "毫秒内无任何动作";
				do_deal_heart_request();
			}
			do_timeout_check();
		});
	}
}
Пример #3
0
void checkFinish(int x)
{
	if (x == 0)
	{
		ElapsedTime = Timer.elapsed();
		Mutex.unlock();
	}
}
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已经运行";
}
Пример #5
0
 void dump(boost::timer::cpu_timer& timer, 
           std::string const& action,
           unsigned count,
           bool warm)
 {
   uint64_t elapsed = timer.elapsed().wall;
   double avg = elapsed < _timer_delay ? 0.0 :
                static_cast<double>(elapsed-_timer_delay)/count;
   _out << _name << "|" << action << "|" << count << "|" 
     << to_string(warm) << "|" << avg << std::endl;
   _out.flush();
 }
Пример #6
0
void M6ProgressImpl::PrintDone()
{
    int width = 80;

    string msg = mTimer.format(0, mAction + " done in %ts cpu / %ws wall");
    if (msg.length() < width)
        msg += string(width - msg.length(), ' ');

    if (IsaTTY())
        cout << '\r' << msg << endl;
    else //if (M6Server::Instance() == nullptr)
        cout << msg << endl;

    M6Status::Instance().SetUpdateStatus(mDatabank, mAction, 1.0f);
}
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();
		}
	});
}
Пример #9
0
	/**
	* 每次呼叫完毕, 需要重置相关资源
	*
	*/
	void realseTrunk()
	{
		m_step = TRK_IDLE;
		m_callTime.start();
		m_call_out_param.reset();
	}
Пример #10
0
	/**
	* \brief 获取通道被占用的时间
	*
	* \return 返回 获取通道被占用的时间, 单位:毫秒
	*/
	std::size_t elpased()
	{
		return (std::size_t)(m_callTime.elapsed().wall / 1000000);
	}
Пример #11
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();
	}
Пример #12
0
	static inline int64_t Get() {
		return boost_clock.elapsed().wall;
	}
Пример #13
0
 void measureElapsed(boost::timer::cpu_timer const& timer) {
   boost::timer::cpu_times elapsed(timer.elapsed());
   const double ns = 1e-9;
   sec = elapsed.user * ns;
   wallSec = elapsed.wall * ns;
 }