title: Get number of bytes read by boost::asio::async_read
body: <p>I am attempting to convert the return value of the function <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/async_read/overload2.htm" rel="nofollow"><code>boost::asio::async_read</code></a> to an <code>int</code> in order to see if I've received any data: </p>
  
  <pre><code>int recvlen = boost::asio::async_read (
      socket_,
      boost::asio::buffer((char*)buffer, 1000),
      boost::bind(&amp;Connection::Receive, this, boost::asio::placeholders::error)
  );
  </code></pre>
  
  <p>Here is that statement in the context of the rest of my code, which does not compile:</p>
  
  <p>.h file:</p>
  
  <pre><code>#ifndef _CONNECTION_H_
  #define _CONNECTION_H_
  
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/enable_shared_from_this.hpp&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;stdint.h&gt;
  
  class Connection 
  {
  public:
      Connection(boost::asio::io_service&amp; io_service);
      ~Connection();
      boost::asio::ip::tcp::socket&amp; socket() {return socket_;}
      void Send(uint8_t* buffer, int length);
      bool Receive();
  
  protected:
      virtual void OnReceived(uint8_t* buffer, int len) = 0;
  
  private:
      boost::asio::ip::tcp::socket socket_;
  };
  
  #endif
  </code></pre>
  
  <p>.cpp file:</p>
  
  <pre><code>#include "Connection.h"
  
  Connection::Connection(boost::asio::io_service&amp; io_service)    
      : socket_(io_service) {}
  
  Connection::~Connection() {}
  
  void Connection::Send(uint8_t* buffer,int length) {
      boost::asio::async_write (
          socket_,
          boost::asio::buffer(buffer, length),
          boost::bind(&amp;Connection::Send, this,boost::asio::placeholders::error)
      );
  }
  
  bool Connection::Receive(){
      uint8_t* buffer = new uint8_t[1000];
  
      //Conversion excerpt
      int recvlen = boost::asio::async_read (
          socket_,
          boost::asio::buffer((char*)buffer, 1000),
          boost::bind(&amp;Connection::Receive, this, boost::asio::placeholders::error)
      );
  
      if (recvlen &lt;= 0) {
          delete[] buffer;
          return false;
      }
  
      this-&gt;OnReceived(buffer, recvlen);
  
      delete[] buffer;
  
      return true;
  }
  </code></pre>
  
  <p>These are the errors this code produces in Visual C++:</p>
  
  <pre><code>error C2825: 'F': must be a class or namespace when followed by '::'    e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp    69
  error C2039: 'result_type' : is not a member of '`global namespace''    e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp    69
  error C2146: syntax error : missing ';' before identifier 'type'    e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp    69
  error C2208: 'boost::_bi::type' : no members defined using this type    e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp    69
  error C1903: unable to recover from previous error(s); stopping compilation e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp    69
  IntelliSense: a value of type "void" cannot be used to initialize an entity of type "int"   d:\c++\ugs\common\connection.cpp    18
  IntelliSense: the #endif for this directive is missing  d:\c++\ugs\common\connection.h  1
  IntelliSense: this declaration has no storage class or type specifier   d:\c++\ugs\common\connection.h  26
  </code></pre>
  
  <p>How can I accomplish what I'm trying to do?  In addition, what do these errors mean and how can I fix them?</p>