As far as I know, the BSD socket interface does not give you this function. You always need to read the buffer. Now, what you can do to not allocate a huge buffer is to read into a smaller buffer in a loop. Something like that:
void skip_impl(tcp::socket& s, int n, boost::function<void(error_code const&)> h , char* buf, error_code const& ec, std::size_t bytes_transferred) { assert(bytes_transferred <= n); n -= bytes_transferred; if (ec || n == 0) { delete[] buf; h(ec); return; } s.async_read_some(boost::asio::buffer(temp, std::min(4096, n)) , boost::bind(&skip_impl, boost::ref(s), n, h, temp, _1, _2)); } void async_skip_bytes(tcp::socket& s, int n, boost::function<void(error_code const&)> h) { char* temp = new char[4096]; s.async_read_some(boost::asio::buffer(temp, std::min(4096, n)) , boost::bind(&skip_impl, boost::ref(s), n, h, temp, _1, _2)); }
This was not passed through the compiler, so there might be silly typos, but this should illustrate the point.
Arvid source share