2013-10-01 112 views
0

我試圖綁定一個讀取處理程序,並加速asio使我瘋狂。Boost asio綁定讀取處理程序

我有以下類

class namenode_registration: 
     public boost::enable_shared_from_this<namenode_registration>, 
     private boost::noncopyable { 
private: 
    [...] 
public: 
    namenode_registration(....); 
    [...] 
    void handle_request_sent(const boost::system::error_code& e); 
    void handle_read_reply_type(boost::asio::mutable_buffers_1& buffer, 
     const boost::system::error_code& e, std::size_t bytes_transferred); 
}; 

通過以下實現:

void namenode_registration::handle_request_sent(
     const boost::system::error_code& e) { 
    if (!e) { 
     boost::asio::async_read(socket_, 
       boost::asio::buffer(buffer_data_, namenode::reply::type_size), 
       boost::bind(&namenode_registration::handle_read_reply_type, 
         shared_from_this(), boost::asio::placeholders::error, 
         boost::asio::placeholders::bytes_transferred)); 
    } 
} 

我真的不明白爲什麼它不會編譯:

In file included from /usr/include/boost/bind.hpp:22:0, 
       from /home/.../datanode/namenode_registration.cpp:9: 
/usr/include/boost/bind/bind.hpp: 
    In instantiation of ‘boost::_bi::result_traits<boost::_bi::unspecified, 
    void (datanode::namenode_registration::*)(boost::asio::mutable_buffers_1&, 
    const boost::system::error_code&, long unsigned int)>’: 
/usr/include/boost/bind/bind_template.hpp:15:48: 
    instantiated from ‘boost::_bi::bind_t<boost::_bi::unspecified, void (datanode::namenode_registration::* 
    (boost::asio::mutable_buffers_1&, const boost::system::error_code&, long unsigned int), 
    boost::_bi::list3<boost::_bi::value<boost::shared_ptr<datanode::namenode_registration> >, 
    boost::arg<1> (*)(), boost::arg<2> (*)()> >’ 
/home/.../datanode/namenode_registration.cpp:50:51: 
    instantiated from here 
/usr/include/boost/bind/bind.hpp:69:37: 
    erreur: ‘void (datanode::namenode_registration::*)(boost::asio::mutable_buffers_1&, 
    const boost::system::error_code&, long unsigned int)’ is not a class, struct, or union type 

回答

4

你的避風港對此功能沒有足夠的參數:

void handle_read_reply_type(boost::asio::mutable_buffers_1& buffer, 
    const boost::system::error_code& e, std::size_t bytes_transferred); 

你缺少緩衝說法:

+0

哦,上帝,你是絕對正確的!我一直在掙扎一個小時。對不起,問這樣一個愚蠢的問題... – Xion345

相關問題