This is precisely the problem null_buffers was designed for.
Sometimes a program must be integrated
with a third-party library that wants
to perform the I/O operations itself.
To facilitate this, Boost.Asio
includes a null_buffers type that can
be used with both read and write
operations. A null_buffers operation
doesn’t return until the I/O object is
“ready” to perform the operation.As an example, to perform a
non-blocking read something like the
following may be used:
ip::tcp::socket socket(my_io_service);
...
ip::tcp::socket::non_blocking nb(true);
socket.io_control(nb);
...
socket.async_read_some(null_buffers(), read_handler);
...
void read_handler(boost::system::error_code ec)
{
if (!ec)
{
std::vector<char> buf(socket.available());
socket.read_some(buffer(buf));
}
}
There’s also an excellent example included in the documentation.