<tfoot id='rZsv6'></tfoot>
  • <i id='rZsv6'><tr id='rZsv6'><dt id='rZsv6'><q id='rZsv6'><span id='rZsv6'><b id='rZsv6'><form id='rZsv6'><ins id='rZsv6'></ins><ul id='rZsv6'></ul><sub id='rZsv6'></sub></form><legend id='rZsv6'></legend><bdo id='rZsv6'><pre id='rZsv6'><center id='rZsv6'></center></pre></bdo></b><th id='rZsv6'></th></span></q></dt></tr></i><div id='rZsv6'><tfoot id='rZsv6'></tfoot><dl id='rZsv6'><fieldset id='rZsv6'></fieldset></dl></div>

  • <legend id='rZsv6'><style id='rZsv6'><dir id='rZsv6'><q id='rZsv6'></q></dir></style></legend>

        • <bdo id='rZsv6'></bdo><ul id='rZsv6'></ul>

        <small id='rZsv6'></small><noframes id='rZsv6'>

        Boost::Asio : io_service.run() vs poll() 或者我如何在 m

        时间:2023-09-17
      1. <tfoot id='JPN4o'></tfoot>

          <bdo id='JPN4o'></bdo><ul id='JPN4o'></ul>

          1. <i id='JPN4o'><tr id='JPN4o'><dt id='JPN4o'><q id='JPN4o'><span id='JPN4o'><b id='JPN4o'><form id='JPN4o'><ins id='JPN4o'></ins><ul id='JPN4o'></ul><sub id='JPN4o'></sub></form><legend id='JPN4o'></legend><bdo id='JPN4o'><pre id='JPN4o'><center id='JPN4o'></center></pre></bdo></b><th id='JPN4o'></th></span></q></dt></tr></i><div id='JPN4o'><tfoot id='JPN4o'></tfoot><dl id='JPN4o'><fieldset id='JPN4o'></fieldset></dl></div>
              <tbody id='JPN4o'></tbody>
                <legend id='JPN4o'><style id='JPN4o'><dir id='JPN4o'><q id='JPN4o'></q></dir></style></legend>
              • <small id='JPN4o'></small><noframes id='JPN4o'>

                1. 本文介绍了Boost::Asio : io_service.run() vs poll() 或者我如何在 mainloop 中集成 boost::asio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前第一次尝试将 boost::asio 用于一些简单的 tcp 网络,但我已经遇到了一些我不确定如何处理的问题.据我了解 io_service.run() 方法基本上是一个循环,它会一直运行直到没有其他事情要做,这意味着它会一直运行直到我释放我的小服务器对象.由于我已经设置了某种主循环,为了简单起见,我宁愿从那里手动更新网络循环,而且我认为 io_service.poll() 会做我想做的事,有点像这样:

                  I am currently trying to use boost::asio for some simple tcp networking for the first time, and I allready came across something I am not really sure how to deal with. As far as I understand io_service.run() method is basically a loop which runs until there is nothing more left to do, which means it will run until I release my little server object. Since I allready got some sort of mainloop set up, I would rather like to update the networking loop manually from there just for the sake of simplicity, and I think io_service.poll() would do what I want, sort of like this:

                  void myApplication::update()
                  {
                       myIoService.poll();
                       //do other stuff
                  }
                  

                  这似乎有效,但我仍然想知道这种方法是否有缺点,因为这似乎不是处理 boost::asios io 服务的常用方法.这是一种有效的方法还是我应该在非阻塞额外线程中使用 io_service.run() ?

                  This seems to work, but I am still wondering if there is a drawback from this method since that does not seem to be the common way to deal with boost::asios io services. Is this a valid approach or should I rather use io_service.run() in a non blocking extra thread?

                  推荐答案

                  使用 io_service::poll 而不是 io_service::run 是完全可以接受的.文档

                  Using io_service::poll instead of io_service::run is perfectly acceptable. The difference is explained in the documentation

                  也可以使用 poll() 函数分派准备好的处理程序,但是没有阻塞.

                  The poll() function may also be used to dispatch ready handlers, but without blocking.

                  请注意,io_service::run 将阻止任何work 留在队列中

                  Note that io_service::run will block if there's any work left in the queue

                  工作类用于通知io_service 工作开始时完成.这确保了io_service 对象的 run() 函数工作正在进行时不会退出,并且它确实在没有时退出剩下的未完成的工作.

                  The work class is used to inform the io_service when work starts and finishes. This ensures that the io_service object's run() function will not exit while work is underway, and that it does exit when there is no unfinished work remaining.

                  io_service::poll 没有表现出这种行为,它只是调用准备好的处理程序.另请注意,您需要调用 io_service::reset 对 io_service:runio_service::poll 的任何后续调用.

                  whereas io_service::poll does not exhibit this behavior, it just invokes ready handlers. Also note that you will need to invoke io_service::reset on any subsequent invocation to io_service:run or io_service::poll.

                  这篇关于Boost::Asio : io_service.run() vs poll() 或者我如何在 mainloop 中集成 boost::asio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:32 位到 16 位浮点转换 下一篇:浮点字节序?

                  相关文章

                  最新文章

                    <bdo id='yf8SM'></bdo><ul id='yf8SM'></ul>

                  <small id='yf8SM'></small><noframes id='yf8SM'>

                2. <legend id='yf8SM'><style id='yf8SM'><dir id='yf8SM'><q id='yf8SM'></q></dir></style></legend>

                3. <tfoot id='yf8SM'></tfoot>

                      <i id='yf8SM'><tr id='yf8SM'><dt id='yf8SM'><q id='yf8SM'><span id='yf8SM'><b id='yf8SM'><form id='yf8SM'><ins id='yf8SM'></ins><ul id='yf8SM'></ul><sub id='yf8SM'></sub></form><legend id='yf8SM'></legend><bdo id='yf8SM'><pre id='yf8SM'><center id='yf8SM'></center></pre></bdo></b><th id='yf8SM'></th></span></q></dt></tr></i><div id='yf8SM'><tfoot id='yf8SM'></tfoot><dl id='yf8SM'><fieldset id='yf8SM'></fieldset></dl></div>