Want to read exactly 8 bytes, no more. I was hoping to automatically do this by giving a container 8 bytes long and let the asio::buffer figure it out, so I don't have to keep track of how many bytes got read.
I don't think it likes me giving it an iterator but I can't think of any other way besides tracking the number of bytes myself, reading into a temporary buffer, and then copying into the final buffer.
Assuming the second sol'n via
asio::read()? I can't figure out how to make it take a parameter of how many bytes max to read.
asio::socket::read_some() reference
std::vector<char> packed_dimensions(8);
while (packed_dimensions.size() < packed_dimensions.capacity())
{
boost::this_thread::interruption_point();
boost::system::error_code connection_error;
size_t len = socket.read_some(boost::asio::buffer(packed_dimensions.end()), connection_error);
if (connection_error == boost::asio::error::eof) break; // Connection closed cleanly by peer.
else if (connection_error) throw boost::system::system_error(connection_error);
}
3>.\Snapstream.cpp(211) : error C2665: 'boost::asio::buffer' : none of the 8 overloads could convert all the argument types
3> C:\Program Files\boost\boost_1_35_0\boost/asio/buffer.hpp(468): could be 'boost::asio::mutable_buffers_1 boost::asio::buffer(const boost::asio::mutable_buffer &)'
3> C:\Program Files\boost\boost_1_35_0\boost/asio/buffer.hpp(488): or 'boost::asio::const_buffers_1 boost::asio::buffer(const boost::asio::const_buffer &)'
3> C:\Program Files\boost\boost_1_35_0\boost/asio/buffer.hpp(771): or 'boost::asio::const_buffers_1 boost::asio::buffer(const std::string &)'
3> while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>)'
3> with
3> [
3> _Ty=char,
3> _Alloc=std::allocator<char>
3> ]
3>.\Snapstream.cpp(211) : error C2780: 'size_t boost::asio::basic_stream_socket<Protocol>::read_some(const MutableBufferSequence &)' : expects 1 arguments - 2 provided
3> with
3> [
3> Protocol=boost::asio::ip::tcp
3> ]
3> C:\Program Files\boost\boost_1_35_0\boost/asio/basic_stream_socket.hpp(639) : see declaration of 'boost::asio::basic_stream_socket<Protocol>::read_some'
3> with
3> [
3> Protocol=boost::asio::ip::tcp
3> ]
I thought of something like this
//size_t len = boost::asio::read(socket, boost::asio::buffer(&*bytes.end(), bytes.capacity() - bytes.size()));
but then the vector wouldn't know it got bigger. Is there an approach I could use with boost::array?