本文整理汇总了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;
}
示例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();
}
示例3: do_run
void do_run()
{
ioService = new boost::asio::io_service();
s = new sopmq::node::server(*ioService, 8481);
s->start();
ioService->run();
}
示例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
)
);
}
示例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));
}
}
示例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));
});
}
}
示例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");
}
}
}
示例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(); });
}
示例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();
}
示例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();
}
示例11: stopLogThread
void stopLogThread()
{
if (LogThreadWork.get())
{
LogThreadWork.reset();
LogIoService.stop();
LogThread.try_join_for(boost::chrono::milliseconds(100));
}
}
示例12: main
int main(int argc, char* argv[]) {
t.async_wait(&print);
io.run();
return EXIT_SUCCESS;
}
示例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()));
}
示例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());
}
}
}
示例15: main
int main()
{
cout << "Hello World!" << endl;
tcp::endpoint endpoint(tcp::v4(), 2015);
ChatServer server(ioservice, endpoint);
ioservice.run();
return 0;
}