title: boost::asio::buffer: Getting the buffer size and preventing buffer overflow?
body: <p>I have the two following functions for sending and receiving packets.</p>
  
  <pre><code>void send(std::string protocol)
  {
      char *request=new char[protocol.size()+1];
      request[protocol.size()] = 0;
      memcpy(request,protocol.c_str(),protocol.size());
  
      request_length = std::strlen(request);
      boost::asio::write(s, boost::asio::buffer(request, request_length));
  }
  void receive()
  {
      char reply[max_length];
      size_t reply_length = boost::asio::read(s, boost::asio::buffer(reply, request_length));
      std::cout &lt;&lt; "Reply is: ";
      std::cout.write(reply, reply_length);
      std::cout &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>The questions pertain to this part <code>boost::asio::buffer(reply, request_length)</code> where the request length is the length of a string which was initially setup when the packet was sent. How do I check the size of the buffer without knowing <code>request_length</code>? Another question is how do I prevent buffer overflow?</p>