[Boost-users] [boost.asio] string iterator not dereferencable using message in async_send_to

79 views
Skip to first unread message

John Urberg

unread,
Aug 11, 2008, 11:08:02 AM8/11/08
to boost...@lists.boost.org
I'm using async_send_to to send multicast messages. When I try to send data in
a std::string, I always get a 'string iterator not dereferencable' assertion
failure. I'm using boost 1.35 and VC9. Here's the code:

// instance variable
string buffer;

// code in method
buffer = BuildHailMessage();
socket.async_send_to(
boost::asio::buffer(buffer),
endpoint,
boost::bind(
&MulticastServer::HandleSendTo,
this,
boost::asio::placeholders::error));

I've also tried using char* buffer, dynamically allocating it based on the
message length and then use std::copy to copy the std::string into the buffer,
but I get heap corruption assertions when trying to delete [] it.

The only way I've gotten this to work is using a fixed char[] buffer.

Is there a way I can use a std::string with async_send_to? Do I need to use a
different type of asio::buffer class?

Thanks,
John

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Ákos Maróy

unread,
Sep 2, 2008, 10:35:39 AM9/2/08
to boost...@lists.boost.org, john-...@idexx.com
John Urberg wrote:
> I'm using async_send_to to send multicast messages. When I try to send data in
> a std::string, I always get a 'string iterator not dereferencable' assertion
> failure. I'm using boost 1.35 and VC9. Here's the code:
>
> // instance variable
> string buffer;
>
> // code in method
> buffer = BuildHailMessage();
> socket.async_send_to(
> boost::asio::buffer(buffer),
> endpoint,
> boost::bind(
> &MulticastServer::HandleSendTo,
> this,
> boost::asio::placeholders::error));
>
> I've also tried using char* buffer, dynamically allocating it based on the
> message length and then use std::copy to copy the std::string into the buffer,
> but I get heap corruption assertions when trying to delete [] it.
>
> The only way I've gotten this to work is using a fixed char[] buffer.
>
> Is there a way I can use a std::string with async_send_to? Do I need to use a
> different type of asio::buffer class?

I'm getting a similar error. Is there a fix to this issue?


Akos

Johan Nilsson

unread,
Sep 3, 2008, 2:50:32 AM9/3/08
to boost...@lists.boost.org
John Urberg wrote:
> I'm using async_send_to to send multicast messages. When I try to
> send data in a std::string, I always get a 'string iterator not
> dereferencable' assertion failure. I'm using boost 1.35 and VC9.
> Here's the code:
>
> // instance variable
> string buffer;
>
> // code in method
> buffer = BuildHailMessage();
> socket.async_send_to(
> boost::asio::buffer(buffer),
> endpoint,
> boost::bind(
> &MulticastServer::HandleSendTo,
> this,
> boost::asio::placeholders::error));

Do you keep the "buffer" string available until async_send_to has actually
completed?

/ Johan

Reply all
Reply to author
Forward
0 new messages