2011-11-04 94 views
2

我們有一些.h文件中如何使用Boost :: asio :: buffer(buf,size)和boost綁定?

template <typename MutableBufferSequence> 
int read_some(boost::asio::ip::tcp::socket& sock, 
    const MutableBufferSequence& buffers) 
{ 
    return sock.read_some(buffers); 
} 

而這樣的代碼,我們希望在我們的類函數成員函數:

boost::packaged_task<int> pt(boost::bind(&http_request::read_some, this, &socket, boost::asio::buffer(buffer, buffer_size))); 

這給了我87個的編譯器錯誤和talls我, boost :: bind不能以這種方式工作。我想知道如何通過boost::bindboost::asio::buffer傳遞給我的函數?

+0

作爲'boost :: bind()'的第三個參數傳遞的''socket變量的類型是什麼? –

回答

1

你必須告訴編譯器你想要綁定哪個read_some。由於它是一個模板,所以當您將它傳遞到bind()時,您必須指定模板參數。

在你的情況下,你想要http_request::read_some<boost::asio::mutable_buffers_1>

作爲一個方面說明,你也傳遞了套接字對象本身的錯誤。你正在傳遞一個指向套接字的指針,並且該函數需要一個引用。而不是通過&socketbind,傳入boost::ref(socket),或者你可以讓函數採用套接字指針而不是引用。

相關問題