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


C++ asio::io_service类代码示例

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


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

示例1: main

int main(int argc, char** argv) {
    init();
    if (handle_args(argc, argv) == 1)
        return 0;

    int processors = boost::thread::hardware_concurrency();

    ioService.post(boost::bind(read_images));
    ioService.post(boost::bind(assign_workers));
    ioService.post(boost::bind(output));

    boost::asio::io_service::work work(ioService);
    for (int i = 0; i < processors; i++) {
        threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService));
    }
    threadpool.join_all();
    return 0;
}
开发者ID:h397wang,项目名称:computer-vision,代码行数:18,代码来源:main.cpp

示例2: subscribeHandler

void subscribeHandler(boost::asio::io_service &ioService, const std::vector<char> &buf)
{
    std::string msg(buf.begin(), buf.end());

    std::cerr << "Message: " << msg << std::endl;

    if( msg == "stop" )
        ioService.stop();
}
开发者ID:lg2779,项目名称:redisclient,代码行数:9,代码来源:async_pubsub.cpp

示例3: do_run

 void do_run()
 {
     ioService = new boost::asio::io_service();
     s = new sopmq::node::server(*ioService, 8481);
     
     s->start();
     
     ioService->run();
 }
开发者ID:InWorldz,项目名称:sopmq,代码行数:9,代码来源:test-operations.cpp

示例4: syncLoad

		void syncLoad(AssetPath path, AssetPromisePtr pr, AssetContentPtr c) {
			Progress::Work w = (Progress::Work)boost::filesystem::file_size(path);
			mngr.prog_.addWork( w );
			// add the loading function to the io_service
			io.post( boost::bind(
				&AssetManager::Loader::asyncLoad,
				this, path, pr, c, w
				)
			);
		}
开发者ID:cristicbz,项目名称:AdventureMiner,代码行数:10,代码来源:AssetManager.cpp

示例5: the_non_blocking_loop

/*! this is why we went through all this efford. You're in control of the event lopp. huray!!!
 * this version is more suitable for realtime applications
 * */
void the_non_blocking_loop(boost::asio::io_service& io_service)
{
	while (true)
	{
		while (io_service.poll_one());

		// do some other work, e.g. sleep
		std::this_thread::sleep_for(std::chrono::milliseconds(100));
	}
}
开发者ID:chimerakang,项目名称:mgsacs,代码行数:13,代码来源:talkServer.cpp

示例6: input_thread

// workarround windows that can use posix stream for stdin
static void input_thread(boost::asio::io_service & io_service)
{
	while (!boost::this_thread::interruption_requested() && !std::cin.eof())
	{
		std::string line;
		std::getline(std::cin, line);
		io_service.post([line]{
			input_got_one_line(ansi_utf8(line));
		});
	}
}
开发者ID:firstblade,项目名称:avbot,代码行数:12,代码来源:input.cpp

示例7: processServiceWork

void PionScheduler::processServiceWork(boost::asio::io_service& service) {
	while (m_is_running) {
		try {
			service.run();
		} catch (std::exception& e) {
			PION_LOG_ERROR(m_logger, e.what());
		} catch (...) {
			PION_LOG_ERROR(m_logger, "caught unrecognized exception");
		}
	}	
}
开发者ID:Beirdo,项目名称:pion,代码行数:11,代码来源:PionScheduler.cpp

示例8: server

    /** Constructor.

        @param log A pointer to a stream to log to, or `nullptr`
        to disable logging.
        
        @param threads The number of threads in the io_service.
    */
    server(std::ostream* log, std::size_t threads)
        : log_(log)
        , sock_(ios_)
        , acceptor_(ios_)
        , work_(ios_)
    {
        thread_.reserve(threads);
        for(std::size_t i = 0; i < threads; ++i)
            thread_.emplace_back(
                [&]{ ios_.run(); });
    }
开发者ID:vinniefalco,项目名称:Beast,代码行数:18,代码来源:websocket_server_async.cpp

示例9: main

int main()
{
	av_start(&io_service);

	int port = 24950; // "av" = 0x6176 = 24950
	// 开启 av协议处理

	boost::asio::spawn(io_service, boost::bind(&async_acceptor, _1, port));

	// 无限睡眠,客户端的话就开始写客户端的逻辑吧
	io_service.run();
}
开发者ID:firstblade,项目名称:avim,代码行数:12,代码来源:router.cpp

示例10: Read_arduino

void Read_arduino()
{
    //program timer for write operations
    tim.expires_from_now(boost::posix_time::seconds(5));
    tim.async_wait(timer_handler);
    //program chain of read operations
    async_read_until(sp,read_buf,'\n',read_handler);
    io.run();
}
开发者ID:Chiroptera,项目名称:scdtr,代码行数:9,代码来源:main.cpp

示例11: stopLogThread

void stopLogThread()
{
    if (LogThreadWork.get())
    {
        LogThreadWork.reset();
        LogIoService.stop();
        LogThread.try_join_for(boost::chrono::milliseconds(100));
    }
}
开发者ID:remap,项目名称:ndnrtc,代码行数:9,代码来源:simple-log.cpp

示例12: main

int main(int argc, char* argv[]) {


	t.async_wait(&print);

	io.run();

	return EXIT_SUCCESS;
}
开发者ID:xtwxy,项目名称:boost-reciple,代码行数:9,代码来源:main.cpp

示例13:

void
Logger::finalizeLogRecord()
{
    if (!recordsQueue_.push(currentLogRecord_.str()))
        sink_->finalizeRecord("[CRITICAL]\tlog queue is full");
        // getOutFileStream() << "[CRITICAL]\tlog queue is full" << std::endl;
    else
        LogIoService.post(boost::bind(&Logger::processLogRecords, shared_from_this()));
}
开发者ID:remap,项目名称:ndnrtc,代码行数:9,代码来源:simple-log.cpp

示例14: 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

示例15: main

int main()
{
    cout << "Hello World!" << endl;

    tcp::endpoint endpoint(tcp::v4(), 2015);
    ChatServer server(ioservice, endpoint);
    ioservice.run();

    return 0;
}
开发者ID:baskeboler,项目名称:cpp_new_features_playground,代码行数:10,代码来源:main.cpp


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