title: boost::buffer with boost::async_write
body: <p>I'm currently having a hard time with boost::asio, specially with the buffers in async_write operations.</p>
  
  <p>When I want to write a packet, I use </p>
  
  <pre><code>async_write(sock_, boost::asio::buffer((char *)&amp;t.getData(), sizeof(T)), boost::bind(&amp;BoostTcpSocket::manageWrite, this, t, boost::asio::placeholders::error));
  </code></pre>
  
  <p>It works fine if i try to send one packet at the time. However if I make two followed call of async_write, it sends me twice the second packet. I have no problem with the packet life cycle.</p>
  
  <p>I think the problem comes from the buffer, i'd like to have a packetQueue buffer instead of one packet buffer.</p>
  
  <p>How can i do this ?
  Thanks for your help</p>
  
  <p>EDIT : here is more info about the code :</p>
  
  <p>Here is how it works :</p>
  
  <pre><code>int  BoostTcpSocket::manageWrite(Packet *t, const boost::system::error_code&amp; error)
  {
      if (!er)
          std::cout &lt;&lt; "Success " &lt;&lt; t.getData() &lt;&lt; std::endl;
      else
          std::cout &lt;&lt; "Error" &lt;&lt; std::endl;
      // delete t;  =&gt; Packet LifeCycle isn't the problem here...
  }
  
  int main()
  {
      boost::asio::ip::tcp::socket    sock_(io);
      sock_.connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1", 8080));
      Packet *p = new Packet("data1");
      Packet *p2 = new Packet("data2");
  
    sock_.async_write(boost::asio::buffer((char *)&amp;p-&gt;getData(), sizeof(Packet::data)), boost::bind(&amp;BoostTcpSocket::manageWrite, this, p, boost::asio::placeholders::error));
    sock_.async_write(boost::asio::buffer((char *)&amp;p2-&gt;getData(), sizeof(Packet::data)), boost::bind(&amp;BoostTcpSocket::manageWrite, this, p2, boost::asio::placeholders::error));
  io.run();
  }
  </code></pre>
  
  <p>This code basically sends me twice the data "data2" even though the output on the server side std::cout is Success data1 Success data2...</p>
  
  <p>EDIT : Apparently i was doing something wrong somewhere else because it is now working.. Thanks everybody for your time &amp; help !</p>