
if you wish to send the whole string, you don't have to pass a size...but the string must be alive until the completion handler is called.
OK, now I try that. I use a member variable string instead of char*. I got another error. I tried to use the same string as buffer for both async_read_some and async_write I guess the string can not be treated as a mutable buffer, so maybe I should keep the original char * buffer for async_read_some and use the string only for outputting with async_write. Is that right? (or any other recommendation?) //NOW data_ member variable is string istead of char* void start() { socket_.async_read_some(boost::asio::buffer(data_), boost::bind(&session::handle_login, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } Error message includes: c:\program files\boost\boost_1_38\boost\asio\detail\win_iocp_socket_service.hpp(1409) : error C2664: 'boost::asio::mutable_buffer::mutable_buffer(const boost::asio::mutable_buffer &)' : cannot convert parameter 1 from 'const boost::asio::const_buffer' to 'const boost::asio::mutable_buffer &' Reason: cannot convert from 'const boost::asio::const_buffer' to 'const boost::asio::mutable_buffer' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called You can see the full error messages I get here: http://pastebin.com/f4ee951e4 TIA Best regards, Ozgur (Oscar) Ozturk www.DrOzturk.com Phone: +1 (908) DROZGUR i.e, +1 (908) 376-9487 On Tue, Jul 21, 2009 at 7:14 AM, Igor R <boost.lists@gmail.com> wrote:
boost::asio::async_write(socket_, boost::asio::buffer(replyString, replyString.size()), boost::bind(&session::handle_write, this, boost::asio::placeholders::error));
I generate the replyString to have results from my database query separated with ^ signs (which is used to tokenize the replyString on the client side...)
string replyString="1^";
boost::asio::buffer does not copy your local string, so the string vanishes before the actual async. write takes place. By the way, if you wish to send the whole string, you don't have to pass a size: boost::asio::buffer(replyString) - but the string must be alive until the completion handler is called. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users