如果我正確理解你的問題,我使用共享指針來存儲數據並將其傳遞給asio處理程序。這是一個UDP接收示例,但傳輸的概念也相同。 (警告這是從內存中寫入和非編譯)
typedef std::vector<uint8_t> DATA_BUF_T;
typedef boost::shared_ptr<DATA_BUF_T> DATA_BUF_PTR_T;
void start_reading()
{
boost::asio::ip::udp::endpoint listen_endpoint (localAddr, usPort);
m_socket.open (listen_endpoint.protocol());
m_socket.bind (listen_endpoint);
// create buffer to store received data
DATA_BUF_PTR_T db (new DATA_BUF_T (max_length));
m_socket.async_receive_from (
boost::asio::buffer (*db, max_length), m_Status.peer,
boost::bind (&handle_receive_from, this,
db,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)
);
}
void handle_receive_from (DATA_BUF_PTR_T db,
const boost::system::error_code &error,
size_t bytes_recvd)
{
if (error)
{
return ;
}
// read data from db
}
來源
2012-02-03 13:19:04
Dan
還有相當有關對象的壽命好的視頻教程(並對其進行管理),通過ASIO製作者在製作:[思考異步:設計應用程序與升壓短耳]( http://blip.tv/boostcon/thinking-asynchronously-designing-applications-with-boost-asio-5250947) – Ghita 2012-02-05 08:12:42