title: How to pass read handler to async_read for Beast websocket?
body: <p>How do I pass in a callback to <code>async_read</code>? I tried the following but it won't
  compile. I based this off of modifying code from the <a href="http://www.boost.org/doc/libs/1_65_1/doc/html/boost_asio/reference/ReadHandler.html" rel="nofollow noreferrer">docs</a></p>
  
  <pre><code>#include &lt;beast/core.hpp&gt;
  #include &lt;beast/http.hpp&gt;
  #include &lt;beast/version.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;beast/websocket.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  using tcp = boost::asio::ip::tcp;
  namespace http = beast::http;
  namespace websocket = beast::websocket;
  
  beast::multi_buffer buffer_;
  
  void read_handler(
      const boost::system::error_code&amp; ec,
      std::size_t bytes_transferred) {
      std::cout &lt;&lt; "READ" &lt;&lt; std::endl;
      std::cout &lt;&lt; beast::buffers(buffer_.data()) &lt;&lt; std::endl;
      if(ec) {
          std::cout &lt;&lt; "error in read " &lt;&lt; ec.message() &lt;&lt; std::endl;
      }
  }
  
  int main() {
      boost::asio::io_service ios;
      tcp::socket sock{ios};
      beast::error_code ec;
      websocket::stream&lt;tcp::socket&amp;&gt; ws{sock};
      beast::multi_buffer buffer;
      ws.async_read(buffer_, boost::bind(&amp;read_handler,
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred
      ));
      return 0;
  }
  </code></pre>
  
  
  
  <pre><code>In file included from /usr/local/include/boost/bind.hpp:22:0,
                   from test.cpp:6:
  /usr/local/include/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2&lt;A1, A2&gt;::operator()(boost::_bi::type&lt;void&gt;, F&amp;, A&amp;, int) [with F = void (*)(const boost::system::error_code&amp;, long unsigned int); A = boost::_bi::rrlist1&lt;const boost::system::error_code&amp;&gt;; A1 = boost::arg&lt;1&gt; (*)(); A2 = boost::arg&lt;2&gt; (*)()]’:
  /usr/local/include/boost/bind/bind.hpp:1306:50:   required from ‘boost::_bi::bind_t&lt;R, F, L&gt;::result_type boost::_bi::bind_t&lt;R, F, L&gt;::operator()(A1&amp;&amp;) [with A1 = const boost::system::error_code&amp;; R = void; F = void (*)(const boost::system::error_code&amp;, long unsigned int); L = boost::_bi::list2&lt;boost::arg&lt;1&gt; (*)(), boost::arg&lt;2&gt; (*)()&gt;; boost::_bi::bind_t&lt;R, F, L&gt;::result_type = void]’
  /home/cc/workspace/Beast/include/beast/websocket/impl/read.ipp:1085:5:   required from ‘void beast::websocket::stream&lt;NextLayer&gt;::read_op&lt;DynamicBuffer, Handler&gt;::operator()(const error_code&amp;, bool) [with DynamicBuffer = beast::basic_multi_buffer&lt;std::allocator&lt;char&gt; &gt;; Handler = boost::_bi::bind_t&lt;void, void (*)(const boost::system::error_code&amp;, long unsigned int), boost::_bi::list2&lt;boost::arg&lt;1&gt; (*)(), boost::arg&lt;2&gt; (*)()&gt; &gt;; NextLayer = boost::asio::basic_stream_socket&lt;boost::asio::ip::tcp&gt;&amp;; beast::error_code = boost::system::error_code]’
  /home/cc/workspace/Beast/include/beast/websocket/impl/read.ipp:1104:26:   required from ‘beast::async_return_type&lt;ReadHandler, void(boost::system::error_code)&gt; beast::websocket::stream&lt;NextLayer&gt;::async_read(DynamicBuffer&amp;, ReadHandler&amp;&amp;) [with DynamicBuffer = beast::basic_multi_buffer&lt;std::allocator&lt;char&gt; &gt;; ReadHandler = boost::_bi::bind_t&lt;void, void (*)(const boost::system::error_code&amp;, long unsigned int), boost::_bi::list2&lt;boost::arg&lt;1&gt; (*)(), boost::arg&lt;2&gt; (*)()&gt; &gt;; NextLayer = boost::asio::basic_stream_socket&lt;boost::asio::ip::tcp&gt;&amp;; beast::async_return_type&lt;ReadHandler, void(boost::system::error_code)&gt; = void]’
  test.cpp:39:6:   required from here
  /usr/local/include/boost/bind/bind.hpp:319:56: error: invalid conversion from ‘boost::arg&lt;2&gt; (*)()’ to ‘boost::arg&lt;1&gt; (*)()’ [-fpermissive]
           unwrapper&lt;F&gt;::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
                                                          ^
  /usr/local/include/boost/bind/bind.hpp:882:11: error:   initializing argument 1 of ‘A1&amp;&amp; boost::_bi::rrlist1&lt;A1&gt;::operator[](boost::arg&lt;1&gt; (*)()) const [with A1 = const boost::system::error_code&amp;]’ [-fpermissive]
       A1 &amp;&amp; operator[] (boost::arg&lt;1&gt; (*) ()) const { return std::forward&lt;A1&gt;( a1_ ); }
             ^
  /usr/local/include/boost/bind/bind.hpp:319:34: error: invalid user-defined conversion from ‘const boost::system::error_code’ to ‘long unsigned int’ [-fpermissive]
           unwrapper&lt;F&gt;::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
                                    ^
  </code></pre>