Boost logo

Boost Users :

Subject: [Boost-users] boost::asio::buffer exception
From: Lloyd Kanakkassery (lloydkl.tech_at_[hidden])
Date: 2010-11-12 00:22:16


Hi,

I want to write some data using boost::asio::write(). write() has two
arguments, one is the stream to which the data to be written and the
other is the data buffer. The data buffer can be created using
boost::asio::buffer() function. When I use it this way it works. Then,
I have tried to wrap boost::asio::bufffer() in my custom function like
this

boost::asio::const_buffers_1 MyBuffer(string msg)
{
        return boost::asio::const_buffers_1(boost::asio::const_buffer(msg.c_str(),msg.length()));
}

The I use this in my asio::write() as

booost::asio::write(mySocket, MyBuffer("hai"));

This program compiles and runs but it throws an exception called "The
system detected an invalid pointer address in attempting to use a
pointer argument in a call". I understand that, it is associated with
the MyBuffer() function. I have checked it with the buffer() function
available in "buffer.hpp". Both are written in the same way, but my
function is throwing exception. Could you give some hint?

Thanks and Regards,
  Lloyd


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net