1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>asio_handler_invoke</title> 5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../reference.html" title="Reference"> 9<link rel="prev" href="asio_handler_deallocate.html" title="asio_handler_deallocate"> 10<link rel="next" href="asio_handler_invoke/overload1.html" title="asio_handler_invoke (1 of 2 overloads)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 15<td align="center"><a href="../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="asio_handler_deallocate.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="asio_handler_invoke/overload1.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.reference.asio_handler_invoke"></a><a class="link" href="asio_handler_invoke.html" title="asio_handler_invoke">asio_handler_invoke</a> 28</h3></div></div></div> 29<p> 30 <a class="indexterm" name="boost_asio.indexterm.asio_handler_invoke"></a> 31(Deprecated: Use 32 the <a class="link" href="associated_executor.html" title="associated_executor"><code class="computeroutput">associated_executor</code></a> 33 trait.) Default invoke function for handlers. 34 </p> 35<p> 36 Default handler invocation hook used for non-const function objects. 37 </p> 38<pre class="programlisting">template< 39 typename Function> 40asio_handler_invoke_is_deprecated <a class="link" href="asio_handler_invoke/overload1.html" title="asio_handler_invoke (1 of 2 overloads)">asio_handler_invoke</a>( 41 Function & function, 42 ... ); 43 <span class="emphasis"><em>» <a class="link" href="asio_handler_invoke/overload1.html" title="asio_handler_invoke (1 of 2 overloads)">more...</a></em></span> 44</pre> 45<p> 46 Default handler invocation hook used for const function objects. 47 </p> 48<pre class="programlisting">template< 49 typename Function> 50asio_handler_invoke_is_deprecated <a class="link" href="asio_handler_invoke/overload2.html" title="asio_handler_invoke (2 of 2 overloads)">asio_handler_invoke</a>( 51 const Function & function, 52 ... ); 53 <span class="emphasis"><em>» <a class="link" href="asio_handler_invoke/overload2.html" title="asio_handler_invoke (2 of 2 overloads)">more...</a></em></span> 54</pre> 55<p> 56 Completion handlers for asynchronous operations are invoked by the <a class="link" href="io_context.html" title="io_context"><code class="computeroutput">io_context</code></a> 57 associated with the corresponding object (e.g. a socket or deadline_timer). 58 Certain guarantees are made on when the handler may be invoked, in particular 59 that a handler can only be invoked from a thread that is currently calling 60 <code class="computeroutput">run()</code> on the corresponding <a class="link" href="io_context.html" title="io_context"><code class="computeroutput">io_context</code></a> 61 object. Handlers may subsequently be invoked through other objects (such 62 as <a class="link" href="io_context__strand.html" title="io_context::strand"><code class="computeroutput">io_context::strand</code></a> 63 objects) that provide additional guarantees. 64 </p> 65<p> 66 When asynchronous operations are composed from other asynchronous operations, 67 all intermediate handlers should be invoked using the same method as the 68 final handler. This is required to ensure that user-defined objects are not 69 accessed in a way that may violate the guarantees. This hooking function 70 ensures that the invoked method used for the final handler is accessible 71 at each intermediate step. 72 </p> 73<p> 74 Implement asio_handler_invoke for your own handlers to specify a custom invocation 75 strategy. 76 </p> 77<p> 78 This default implementation invokes the function object like so: 79 </p> 80<pre class="programlisting">function(); 81</pre> 82<p> 83 If necessary, the default implementation makes a copy of the function object 84 so that the non-const operator() can be used. 85 </p> 86<h5> 87<a name="boost_asio.reference.asio_handler_invoke.h0"></a> 88 <span class="phrase"><a name="boost_asio.reference.asio_handler_invoke.example"></a></span><a class="link" href="asio_handler_invoke.html#boost_asio.reference.asio_handler_invoke.example">Example</a> 89 </h5> 90<pre class="programlisting">class my_handler; 91 92template <typename Function> 93void asio_handler_invoke(Function function, my_handler* context) 94{ 95 context->strand_.dispatch(function); 96} 97</pre> 98<h5> 99<a name="boost_asio.reference.asio_handler_invoke.h1"></a> 100 <span class="phrase"><a name="boost_asio.reference.asio_handler_invoke.requirements"></a></span><a class="link" href="asio_handler_invoke.html#boost_asio.reference.asio_handler_invoke.requirements">Requirements</a> 101 </h5> 102<p> 103 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/handler_invoke_hook.hpp</code> 104 </p> 105<p> 106 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code> 107 </p> 108</div> 109<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 110<td align="left"></td> 111<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 112 Kohlhoff<p> 113 Distributed under the Boost Software License, Version 1.0. (See accompanying 114 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 115 </p> 116</div></td> 117</tr></table> 118<hr> 119<div class="spirit-nav"> 120<a accesskey="p" href="asio_handler_deallocate.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="asio_handler_invoke/overload1.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 121</div> 122</body> 123</html> 124