
11 Nov
2009
11 Nov
'09
9:04 a.m.
Socket.async_send_to(boost::asio::buffer(*SharedBuffer, BufferSize), DestinationEndpoint, boost::bind(&MyClass::OnPacketSent, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); // Shared buffer goes out of scope here, immediately!
You do not copy SharedBuffer, so it's destroyed when goes out of scope. If you want SharedBuffer to outlive the handler, you can store the shared_ptr within the handler, like this: // UNTESTED! using boost::bind; using boost::protect; Socket.async_send_to(buffer(*SharedBuffer, BufferSize), DestinationEndpoint, bind(protect(bind(&MyClass::OnPacketSent, this, _1, _2)), _1, _2, SharedBuffer)); // you can revert back to the asio placeholders