views:

63

answers:

1

It seems that since boost 1.40.0 there has been a change to the way that the the async_read_some() call works.

Previously, you could pass in a null_buffer and you would get a callback when there was data to read, but without the framework reading the data into any buffer (because there wasn't one!). This basically allowed you to write code that acted like a select() call, where you would be told when your socket had some data on it.

In the new code the behaviour has been changed to work in the following way:

If the total size of all buffers in the sequence mb is 0, the asynchronous read operation shall complete immediately and pass 0 as the argument to the handler that specifies the number of bytes read.

This means that my old (and incidentally, the method shown in this official example) way of detecting data on the socket no longer works. The problem for me is that I need a way detecting this because I've layered my own streaming classes on-top of the asio socket streams and as such, I cannot just read data off the sockets that my streams will expect to be there. The only workaround I can think of right now is to read a single byte, store it and when my stream classes then request some bytes, return that byte if one is set: not pretty.

Does anyone know of a better way to implement this kind of behaviour under the latest boost.asio code?

+1  A: 

My quick test with an official example with boost-1.41 works... So I think it still should work (if you use null_buffers)

Artyom