当前位置: 首页>>代码示例>>C++>>正文


C++ io_service::run_one方法代码示例

本文整理汇总了C++中boost::asio::io_service::run_one方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::run_one方法的具体用法?C++ io_service::run_one怎么用?C++ io_service::run_one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::asio::io_service的用法示例。


在下文中一共展示了io_service::run_one方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: thread_fun

	void thread_fun()
	{
		for (;;)
		{
			error_code ec;
			tcp::endpoint from;
			tcp::socket socket(m_ios);
			condition_variable cond;
			bool done = false;
			m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
			while (!done)
			{
				m_ios.run_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "Error accepting connection on peer socket: %s\n", ec.message().c_str());
				return;
			}

			fprintf(stderr, "%s: incoming peer connection\n", time_now_string());
			++m_peer_requests;
			socket.close(ec);
		}
	}
开发者ID:SergeyKrivohatskiy,项目名称:real_time_torrent,代码行数:30,代码来源:peer_server.cpp

示例2: run_service

inline void run_service( boost::asio::io_service & io_service) {
    h_timer timer( io_service, boost::chrono::seconds(0) );
    timer.async_wait( boost::bind( timer_handler, boost::ref( timer) ) );
    while (true)
    {
        boost::system::error_code ec;
        std::size_t num = io_service.run_one(ec);
        if (num == 0)
        {
            return;
        }
        boost::this_fiber::yield();
    }
}
开发者ID:654894017,项目名称:fiberproxy,代码行数:14,代码来源:loop.hpp

示例3: thread_fun

	void thread_fun()
	{
		char buffer[2000];
	
		for (;;)
		{
			error_code ec;
			udp::endpoint from;
			size_t bytes_transferred;
			bool done = false;
			m_socket.async_receive_from(
				asio::buffer(buffer, sizeof(buffer)), from, 0
				, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
			while (!done)
			{
				m_ios.run_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "Error receiving on DHT socket: %s\n", ec.message().c_str());
				return;
			}

			try
			{
				entry msg = bdecode(buffer, buffer + bytes_transferred);

#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
				std::cerr << msg << std::endl;
#endif
				++m_dht_requests;
			}
			catch (std::exception& e)
			{
				fprintf(stderr, "failed to decode DHT message: %s\n", e.what());
			}
		}
	}
开发者ID:SergeyKrivohatskiy,项目名称:real_time_torrent,代码行数:43,代码来源:dht_server.cpp

示例4: IdleService

static inline void avloop_run(boost::asio::io_service& io_service)
{
	using namespace ::detail;

	if (!boost::asio::has_service<IdleService>(io_service))
		boost::asio::add_service(io_service, new IdleService(io_service));

	while (!io_service.stopped())
	{
		if(!boost::asio::use_service<IdleService>(io_service).has_idle())
		{
			if (!io_service.run_one())
				break;
		}
		else
		{
			while (io_service.poll());
			// 执行 idle handler!
			boost::asio::use_service<IdleService>(io_service).poll_one();
		}
	}
}
开发者ID:Artoria2e5,项目名称:avbot,代码行数:22,代码来源:avloop.hpp

示例5: service

        service( boost::asio::io_service & io_svc) :
            boost::asio::io_service::service( io_svc),
            work_{ new boost::asio::io_service::work( io_svc) } {
            io_svc.post([&io_svc](){
//]
//[asio_rr_service_lambda
                while ( ! io_svc.stopped() ) {
                    if ( boost::fibers::has_ready_fibers() ) {
                        // run all pending handlers in round_robin
                        while ( io_svc.poll() );
                        // run pending (ready) fibers
                        this_fiber::yield();
                    } else {
                        // run one handler inside io_service
                        // if no handler available, block this thread
                        if ( ! io_svc.run_one() ) {
                            break;
                        }
                    }
                }
//]
//[asio_rr_service_bottom
            });
        }
开发者ID:BestSilent,项目名称:eos,代码行数:24,代码来源:round_robin.hpp


注:本文中的boost::asio::io_service::run_one方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。