What is the way to access the data contained in a stream buffer?
This is the relevant code: boost::asio::streambuf request; std::ostream request_stream(&request); request_stream << "GET " << argv[2] << " HTTP/1.0\r\n"; request_stream << "Host: " << argv[1] << "\r\n"; request_stream << "Accept: */*\r\n"; request_stream << "Connection: close\r\n\r\n"; // Send the request. boost::asio::write(socket, request); How can I convert the 'request.data' into a string or something? TIA, -Ramon
Ramon F Herrera wrote:
This is the relevant code:
boost::asio::streambuf request; std::ostream request_stream(&request); request_stream << "GET " << argv[2] << " HTTP/1.0\r\n"; request_stream << "Host: " << argv[1] << "\r\n"; request_stream << "Accept: */*\r\n"; request_stream << "Connection: close\r\n\r\n";
// Send the request. boost::asio::write(socket, request);
How can I convert the 'request.data' into a string or something?
TIA,
-Ramon
I have a follow-up question of a more general nature. I think the Boost libraries are the greatest thing since sliced bread, but there are times when a simpler approach will suffice. We can see in these 2 lines of code that we are mixing STL with Boost: boost::asio::streambuf request; std::ostream request_stream(&request); Is there any STL class that can be used above, instead of boost::asio::streambuf? I am trying to have a better feeling for the different implementations and choices among streams and buffers. TIA, -Ramon
We can see in these 2 lines of code that we are mixing STL with Boost:
boost::asio::streambuf request; std::ostream request_stream(&request);
Is there any STL class that can be used above, instead of boost::asio::streambuf?
I am trying to have a better feeling for the different implementations and choices among streams and buffers.
asio socket's member functions that write data to the socket, like async_write_some() or async_send(), get a ConstBufferSequence-complient buffer as a parameter: http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/basic_str... http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/ConstBuff... There's a "buffer" class that can adapt virtually any physical buffer type to comply with ConstBufferSequence: http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/buffer.ht... The free function boost::asio::write() is just a convenience function that one of its overloads take an asio::streambuf: http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/write.htm...
We can see in these 2 lines of code
that we are mixing STL with Boost:
boost::asio::streambuf request; std::ostream request_stream(&request);
Is there any STL class that can be used above, instead of boost::asio::streambuf?
I can see the standard library here, but not the STL ;) Matthieu -- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher
participants (3)
-
Igor R
-
Matthieu Brucher
-
Ramon F Herrera