如何使用boost :: asio :: io_service :: run_one() [英] How to use boost::asio::io_service::run_one()
问题描述
我正在阅读 boost :: asio :: io_service :: run_one(),并对其功能块的含义感到困惑。
I was reading up on boost::asio::io_service::run_one() and am confused by what it means by the function block. What has been blocked and where is the handler defined?
推荐答案
我正在阅读boost: :asio :: io_service :: run_one(),并对其功能块的含义感到困惑。被阻止的内容
I was reading up on boost::asio::io_service::run_one() and am confused by what it means by the function block. What has been blocked
被阻止的意思是 run_one()
阻止,直到完成一个
Blocked means run_one()
blocks until it completes one handler.
在哪里定义处理程序?
and where is the handler defined?
不是。 在逻辑上在文档中进行了描述一个>。处理程序是服务中待处理的任何操作。因此,如果您这样做:
It isn't. Logically it's described in the documentation. A handler is whatever action is pending in the service. So, if you do:
void foo() { /*.... */ }
void bar() { /*.... */ }
io_service svc;
svc.post(foo);
svc.post(bar);
现在第一次拨打电话
svc.run_one();
阻塞直到 foo
完成。
svc.run_one();
将阻塞,直到 bar
完成。之后, run_one()
将不会阻塞,仅返回0。如果使该服务保持不变,例如:
will block until bar
is completed. After that, run_one()
will NOT block and just return 0. If you make the service stay around, e.g.:
io_service::work keep_around(svc);
svc.run_one();
在执行其他操作之前将一直处于阻止状态。
would block until some other action was posted.
这篇关于如何使用boost :: asio :: io_service :: run_one()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!