1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Connect handler requirements</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="ConnectCondition.html" title="Connect condition requirements"> 10<link rel="next" href="ConstBufferSequence.html" title="Constant buffer sequence requirements"> 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="ConnectCondition.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="ConstBufferSequence.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.ConnectHandler"></a><a class="link" href="ConnectHandler.html" title="Connect handler requirements">Connect handler 28 requirements</a> 29</h3></div></div></div> 30<p> 31 A connect handler must meet the requirements for a <a class="link" href="Handler.html" title="Handlers">handler</a>. 32 A value <code class="computeroutput">h</code> of a connect handler class should work correctly in 33 the expression <code class="computeroutput">h(ec)</code>, where <code class="computeroutput">ec</code> is an lvalue of 34 type <code class="computeroutput">const error_code</code>. 35 </p> 36<h5> 37<a name="boost_asio.reference.ConnectHandler.h0"></a> 38 <span class="phrase"><a name="boost_asio.reference.ConnectHandler.examples"></a></span><a class="link" href="ConnectHandler.html#boost_asio.reference.ConnectHandler.examples">Examples</a> 39 </h5> 40<p> 41 A free function as a connect handler: 42 </p> 43<pre class="programlisting">void connect_handler( 44 const boost::system::error_code& ec) 45{ 46 ... 47} 48</pre> 49<p> 50 A connect handler function object: 51 </p> 52<pre class="programlisting">struct connect_handler 53{ 54 ... 55 void operator()( 56 const boost::system::error_code& ec) 57 { 58 ... 59 } 60 ... 61}; 62</pre> 63<p> 64 A lambda as a connect handler: 65 </p> 66<pre class="programlisting">socket.async_connect(..., 67 [](const boost::system::error_code& ec) 68 { 69 ... 70 }); 71</pre> 72<p> 73 A non-static class member function adapted to a connect handler using <code class="computeroutput">std::bind()</code>: 74 </p> 75<pre class="programlisting">void my_class::connect_handler( 76 const boost::system::error_code& ec) 77{ 78 ... 79} 80... 81socket.async_connect(..., 82 std::bind(&my_class::connect_handler, 83 this, std::placeholders::_1)); 84</pre> 85<p> 86 A non-static class member function adapted to a connect handler using <code class="computeroutput">boost::bind()</code>: 87 </p> 88<pre class="programlisting">void my_class::connect_handler( 89 const boost::system::error_code& ec) 90{ 91 ... 92} 93... 94socket.async_connect(..., 95 boost::bind(&my_class::connect_handler, 96 this, boost::asio::placeholders::error)); 97</pre> 98</div> 99<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 100<td align="left"></td> 101<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 102 Kohlhoff<p> 103 Distributed under the Boost Software License, Version 1.0. (See accompanying 104 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>) 105 </p> 106</div></td> 107</tr></table> 108<hr> 109<div class="spirit-nav"> 110<a accesskey="p" href="ConnectCondition.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="ConstBufferSequence.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 111</div> 112</body> 113</html> 114