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

      <bdo id='DSSj4'></bdo><ul id='DSSj4'></ul>
    <legend id='DSSj4'><style id='DSSj4'><dir id='DSSj4'><q id='DSSj4'></q></dir></style></legend>

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

    1. <tfoot id='DSSj4'></tfoot>

        asio::async_write 和链

        asio::async_write and strand(asio::async_write 和链)
        <i id='SSGYG'><tr id='SSGYG'><dt id='SSGYG'><q id='SSGYG'><span id='SSGYG'><b id='SSGYG'><form id='SSGYG'><ins id='SSGYG'></ins><ul id='SSGYG'></ul><sub id='SSGYG'></sub></form><legend id='SSGYG'></legend><bdo id='SSGYG'><pre id='SSGYG'><center id='SSGYG'></center></pre></bdo></b><th id='SSGYG'></th></span></q></dt></tr></i><div id='SSGYG'><tfoot id='SSGYG'></tfoot><dl id='SSGYG'><fieldset id='SSGYG'></fieldset></dl></div>
          <tbody id='SSGYG'></tbody>
      1. <tfoot id='SSGYG'></tfoot>

      2. <small id='SSGYG'></small><noframes id='SSGYG'>

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

                <bdo id='SSGYG'></bdo><ul id='SSGYG'></ul>
                1. 本文介绍了asio::async_write 和链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  asio::async_write(m_socket, asio::buffer(buf, bytes),
                                  custom_alloc(m_strand.wrap(custom_alloc(_OnSend))));
                  

                  这段代码是否保证async_write内部的所有异步操作处理程序(调用async_write_some)都通过strand调用?(或者它只是为了 my_handler?)

                  Does this code guarantee that all asynchronous operation handlers(calls to async_write_some) inside async_write are called through strand? (or it's just for my_handler?)

                  推荐答案

                  使用以下代码:

                  asio::async_write(stream, ..., custom_alloc(m_strand.wrap(...)));
                  

                  对于这个组合操作,如果以下所有条件都为真,所有对 stream.async_write_some() 的调用都将在 m_strand 内调用:

                  For this composed operation, all calls to stream.async_write_some() will be invoked within m_strand if all of the following conditions are true:

                  • 发起的 async_write(...) 调用在 m_strand() 中运行:

                  assert(m_strand.running_in_this_thread());
                  asio::async_write(stream, ..., custom_alloc(m_strand.wrap(...)));
                  

                2. custom_alloc 的返回类型是:

                  • strand::wrap()

                  template <typename Handler> 
                  Handler custom_alloc(Handler) { ... }
                  

                3. 一个自定义处理程序,用于适当链接 asio_handler_invoke():

                  template <class Handler>
                  class custom_handler
                  {
                  public:
                    custom_handler(Handler handler)
                      : handler_(handler)
                    {}
                  
                    template <class... Args>
                    void operator()(Args&&... args)
                    {
                      handler_(std::forward<Args>(args)...);
                    }
                  
                    template <typename Function>
                    friend void asio_handler_invoke(
                      Function intermediate_handler,
                      custom_handler* my_handler)
                    {
                      // Support chaining custom strategies incase the wrapped handler
                      // has a custom strategy of its own.
                      using boost::asio::asio_handler_invoke;
                      asio_handler_invoke(intermediate_handler, &my_handler->handler_);
                    }
                  
                  private:
                    Handler handler_;
                  };
                  
                  template <typename Handler>
                  custom_handler<Handler> custom_alloc(Handler handler)
                  {
                    return {handler};
                  }
                  

                4. 请参阅此答案以了解有关链的更多详细信息,以及this 回答有关 asio_handler_invoke 的详细信息.

                  See this answer for more details on strands, and this answer for details on asio_handler_invoke.

                  这篇关于asio::async_write 和链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                    <legend id='Tkpw0'><style id='Tkpw0'><dir id='Tkpw0'><q id='Tkpw0'></q></dir></style></legend>

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

                    • <bdo id='Tkpw0'></bdo><ul id='Tkpw0'></ul>
                        1. <tfoot id='Tkpw0'></tfoot>

                            <tbody id='Tkpw0'></tbody>

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