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