title: boost::asio async server design
body: <p>Currently I'm using design when server reads first 4 bytes of stream then read N bytes after header decoding.</p>
  
  <p>But I found that time between first async_read and second read is 3-4 ms. I just printed in console timestamp from callbacks for measuring. I sent 10 bytes of data in total.  Why it takes so much time to read?</p>
  
  <blockquote>
    <p>I running it in debug mode but I think that 1 connection for debug is
    not so much to have a 3 ms delay  between reads from socket. Maybe I need
    another approach to cut TCP stream on "packets"?</p>
  </blockquote>
  
  <p><strong>UPDATE:</strong> I post some code here</p>
  
  <pre><code>void parseHeader(const boost::system::error_code&amp; error)
          {
              cout&lt;&lt;"[parseHeader] "&lt;&lt;lib::GET_SERVER_TIME()&lt;&lt;endl;
              if (error) {
                  close();
                  return;
              }
              GenTCPmsg::header result = msg.parseHeader();
              if (result.error == GenTCPmsg::parse_error::__NO_ERROR__) {
                  msg.setDataLength(result.size);
                  boost::asio::async_read(*socket, 
                      boost::asio::buffer(msg.data(), result.size),
                      (*_strand).wrap(
                      boost::bind(&amp;ConnectionInterface::parsePacket, shared_from_this(), boost::asio::placeholders::error)));
              } else {
                  close();
              }
          }
          void parsePacket(const boost::system::error_code&amp; error)
          {
              cout&lt;&lt;"[parsePacket] "&lt;&lt;lib::GET_SERVER_TIME()&lt;&lt;endl;
              if (error) {
                  close();
                  return;
              }
              protocol-&gt;parsePacket(msg);
              msg.flush();
              boost::asio::async_read(*socket, 
                  boost::asio::buffer(msg.data(), config::HEADER_SIZE),
                  (*_strand).wrap(
                  boost::bind(&amp;ConnectionInterface::parseHeader, shared_from_this(), boost::asio::placeholders::error)));
          }
  </code></pre>
  
  <p>As you see unix timestamps differ in 3-4 ms. I want to understand why so many time elapse between parseHeader and parsePacket. This is not a client problem, summary data is 10 bytes, but i cant sent much much more, delay is exactly between calls. I'm using flash client version 11. What i do is just send ByteArray through opened socket. I don't sure that delays on client. I send all 10 bytes at once. How can i debug where actual delay is?</p>