boost::asio::buffer + std::wstring

Hi, I'm sending unicode text over a socket using boost::asio::async_write and boost::asio::buffer however only 1/4 of the string ends up at the receiver. What must I do so that all bytes are sent? Thanks!

"content", etc are std::wstring objects. std::vectorboost::asio::const_buffer reply::to_buffers() { std::vectorboost::asio::const_buffer buffers; buffers.push_back(status_strings::to_buffer(status)); buffers.push_back(boost::asio::buffer(misc_strings::crlf)); buffers.push_back(boost::asio::buffer(content)); return buffers; } and ... request_handler_.handle_request(req, reply_); boost::asio::async_write(socket_, reply_.to_buffers(), strand_.wrap( boost::bind(&connection::handle_write, shared_from_this(), _1)) );
From: boost.lists@gmail.com Date: Tue, 27 Dec 2011 09:02:26 +0200 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio::buffer + std::wstring
I'm sending unicode text over a socket using boost::asio::async_write and boost::asio::buffer however only 1/4 of the string ends up at the receiver. What must I do so that all bytes are sent?
Where is the code? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Please, don't top-tpost.
"content", etc are std::wstring objects.
Are you sure they outlive the async operation (eg. aren't they local objects)?
std::vectorboost::asio::const_buffer reply::to_buffers() { std::vectorboost::asio::const_buffer buffers;
buffers.push_back(status_strings::to_buffer(status)); buffers.push_back(boost::asio::buffer(misc_strings::crlf)); buffers.push_back(boost::asio::buffer(content));
return buffers; } and ... request_handler_.handle_request(req, reply_);
boost::asio::async_write(socket_, reply_.to_buffers(), strand_.wrap( boost::bind(&connection::handle_write, shared_from_this(), _1))
Check also that you don't call async_write() when another async_write() to the same socket is in progress.

----------------------------------------
From: boost.lists@gmail.com Date: Wed, 28 Dec 2011 09:20:48 +0200 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio::buffer + std::wstring
Please, don't top-tpost.
"content", etc are std::wstring objects.
Are you sure they outlive the async operation (eg. aren't they local objects)? Yes
std::vector reply::to_buffers() { std::vector buffers;
buffers.push_back(status_strings::to_buffer(status)); buffers.push_back(boost::asio::buffer(misc_strings::crlf)); buffers.push_back(boost::asio::buffer(content));
return buffers; } and ... request_handler_.handle_request(req, reply_);
boost::asio::async_write(socket_, reply_.to_buffers(), strand_.wrap( boost::bind(&connection::handle_write, shared_from_this(), _1))
Check also that you don't call async_write() when another async_write() to the same socket is in progress. The issue isn't writing nor object lifetime. If I use std::string objects the receiver gets all of the content but with std::wstring only 1/4 of the content is received. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

The issue isn't writing nor object lifetime. If I use std::string objects the receiver gets all of the content but with std::wstring only 1/4 of the content is received.
It's the same buffer() function both for std::string and std::wstring:
template

----------------------------------------
From: boost.lists@gmail.com Date: Wed, 28 Dec 2011 11:48:27 +0200 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio::buffer + std::wstring
The issue isn't writing nor object lifetime. If I use std::string objects the receiver gets all of the content but with std::wstring only 1/4 of the content is received.
It's the same buffer() function both for std::string and std::wstring: Right. On linux the data loss is 3/4 and on windows it's 1/2. Coincidently wchar_t is 4 bytes on linux and 2 bytes on windows. It seems as if boost::asio::buffer is treating it internally as 1 byte. :-/
template inline const_buffers_1 buffer(const std::basic_string Allocator>& data); _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Igor R
-
Luke Walker