WaitHandler.html 5.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Wait handler requirements</title>
  5. <link rel="stylesheet" href="../../boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
  7. <link rel="home" href="../../index.html" title="Asio">
  8. <link rel="up" href="../reference.html" title="Reference">
  9. <link rel="prev" href="WaitableTimerService.html" title="Waitable timer service requirements">
  10. <link rel="next" href="WaitTraits.html" title="Wait traits requirements">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../asio.png"></td></tr></table>
  14. <hr>
  15. <div class="spirit-nav">
  16. <a accesskey="p" href="WaitableTimerService.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="WaitTraits.html"><img src="../../next.png" alt="Next"></a>
  17. </div>
  18. <div class="section">
  19. <div class="titlepage"><div><div><h3 class="title">
  20. <a name="asio.reference.WaitHandler"></a><a class="link" href="WaitHandler.html" title="Wait handler requirements">Wait handler requirements</a>
  21. </h3></div></div></div>
  22. <p>
  23. A wait handler must meet the requirements for a <a class="link" href="Handler.html" title="Handlers">handler</a>.
  24. A value <code class="computeroutput"><span class="identifier">h</span></code> of a wait handler
  25. class should work correctly in the expression <code class="computeroutput"><span class="identifier">h</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>,
  26. where <code class="computeroutput"><span class="identifier">ec</span></code> is an lvalue of
  27. type <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">error_code</span></code>.
  28. </p>
  29. <h5>
  30. <a name="asio.reference.WaitHandler.h0"></a>
  31. <span><a name="asio.reference.WaitHandler.examples"></a></span><a class="link" href="WaitHandler.html#asio.reference.WaitHandler.examples">Examples</a>
  32. </h5>
  33. <p>
  34. A free function as a wait handler:
  35. </p>
  36. <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">wait_handler</span><span class="special">(</span>
  37. <span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
  38. <span class="special">{</span>
  39. <span class="special">...</span>
  40. <span class="special">}</span>
  41. </pre>
  42. <p>
  43. A wait handler function object:
  44. </p>
  45. <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">wait_handler</span>
  46. <span class="special">{</span>
  47. <span class="special">...</span>
  48. <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span>
  49. <span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
  50. <span class="special">{</span>
  51. <span class="special">...</span>
  52. <span class="special">}</span>
  53. <span class="special">...</span>
  54. <span class="special">};</span>
  55. </pre>
  56. <p>
  57. A non-static class member function adapted to a wait handler using <code class="computeroutput"><span class="identifier">bind</span><span class="special">()</span></code>:
  58. </p>
  59. <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">my_class</span><span class="special">::</span><span class="identifier">wait_handler</span><span class="special">(</span>
  60. <span class="keyword">const</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
  61. <span class="special">{</span>
  62. <span class="special">...</span>
  63. <span class="special">}</span>
  64. <span class="special">...</span>
  65. <span class="identifier">socket</span><span class="special">.</span><span class="identifier">async_wait</span><span class="special">(...,</span>
  66. <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(&amp;</span><span class="identifier">my_class</span><span class="special">::</span><span class="identifier">wait_handler</span><span class="special">,</span>
  67. <span class="keyword">this</span><span class="special">,</span> <span class="identifier">asio</span><span class="special">::</span><span class="identifier">placeholders</span><span class="special">::</span><span class="identifier">error</span><span class="special">));</span>
  68. </pre>
  69. </div>
  70. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  71. <td align="left"></td>
  72. <td align="right"><div class="copyright-footer">Copyright &#169; 2003-2014 Christopher M. Kohlhoff<p>
  73. Distributed under the Boost Software License, Version 1.0. (See accompanying
  74. 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>)
  75. </p>
  76. </div></td>
  77. </tr></table>
  78. <hr>
  79. <div class="spirit-nav">
  80. <a accesskey="p" href="WaitableTimerService.html"><img src="../../prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../home.png" alt="Home"></a><a accesskey="n" href="WaitTraits.html"><img src="../../next.png" alt="Next"></a>
  81. </div>
  82. </body>
  83. </html>