Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made this same point as a comment but I figured it would be worth expanding into an answer. Posting the snippets of code you have are not terribly helpful, they don't give us the full picture. For example, the following concepts are not clear to me:</p> <ol> <li>You're not checking the <code>bytes_transferred</code> parameter in your <code>async_read_some</code> handler. This is <em>very important</em> because even though you tell it to read <code>n</code> bytes it <a href="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/reference/basic_stream_socket/async_read_some.html" rel="nofollow">can</a> return when reading <code>n - x</code> bytes where <code>x &lt;= n</code>. As the <a href="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/reference/basic_stream_socket/async_read_some.html" rel="nofollow">documentation states</a>, you should consider using one of the composed operations like the <code>async_read</code> <a href="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/reference/async_read.html" rel="nofollow">free function</a>.</li> <li>you're using <a href="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/overview/core/allocation.html" rel="nofollow">custom memory allocations</a> for your asynchronous read operations, presumably based on the <a href="http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/example/allocation/server.cpp" rel="nofollow">example provided</a>. Why do you need that?</li> <li>buffer lifetime. Ex: do your buffers stay in scope until the <code>async_read</code> handler is invoked?</li> <li>object lifetime. Ex: are you using <code>shared_ptr</code> properly? Is the <code>io_service</code> in scope for the entirety of its event loop?</li> <li>are you using a single <code>io_service</code> per process or one per thread?</li> <li>why you need threads? Typically it's easier to understand asynchronous programming in a single threaded context first.</li> </ol> <p>All of these are very important concepts to get right when using Boost.Asio. Part of debugging is boiling down a perceived problem into a smaller reproducer. This is useful both on Stack Overflow and for becomming a good programmer in general. It will help you understand the problem, and also help <strong>us</strong> help you find it. I strongly suggest you spend some effort on making a smaller reproducible example that we can compile. If that's not possible, consider using multiple threads only after you have proved a single threaded scenario works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload