c++ - boost::bind member function WriteHandlerCheck error -
i'm trying bind function boost::asio::async_write
, got semantic error in write.hpp
class client{ public: client(const int &frame_,char* buf,const int& size_){ frame=frame_; b=buf; size=size_; } void donothing(){ //? } void handle(const boost::system::error_code& error,std::size_t bytes_transferred ){ //should handle socket being closed , data in buffer being released cout<<"bytes sent: "<<bytes_transferred<<endl; cout<<error<<endl; } void runclient() { try { tcp::resolver resolver(io_service); tcp::resolver::query query(tcp::v4(), host, port); tcp::resolver::iterator iterator = resolver.resolve(query); s=new boost::asio::ip::tcp::socket(io_service); boost::asio::connect(*s, iterator); std::cout << "sending png: frame"<<frame<<" size: "<<size<<"bytes ... "<<endl; int number_to_send = size; // put value int converted_number = htonl(number_to_send); boost::asio::async_write(*s,boost::asio::buffer(&converted_number, sizeof(converted_number)),&client::donothing); boost::asio::async_write(*s, boost::asio::buffer(b, size), boost::bind(&client::handle, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); std::cout << "done!"<<endl; } catch (std::exception& e) { std::cerr << "exception: " << e.what() << "\n"; } } private: enum { max_length = 1024 }; string port="1112"; string host="157.193.215.48"; char * b; int size; int frame; boost::asio::io_service io_service; boost::asio::ip::tcp::socket* s; };
this code has no syntax errors, give error in write.hpp when compiling:
/usr/local/include/boost/asio/impl/write.hpp:615:3: called object type 'void (client::*)()' not function or function pointer.
affected code:
template <typename asyncwritestream, typename constbuffersequence, typename writehandler> inline boost_asio_initfn_result_type(writehandler, void (boost::system::error_code, std::size_t)) async_write(asyncwritestream& s, const constbuffersequence& buffers, boost_asio_move_arg(writehandler) handler) { // if error on following line means handler // not meet documented type requirements writehandler. boost_asio_write_handler_check(writehandler, handler) type_check; detail::async_result_init< writehandler, void (boost::system::error_code, std::size_t)> init( boost_asio_move_cast(writehandler)(handler)); detail::write_op<asyncwritestream, constbuffersequence, detail::transfer_all_t, boost_asio_handler_type( writehandler, void (boost::system::error_code, std::size_t))>( s, buffers, transfer_all(), init.handler)( boost::system::error_code(), 0, 1); return init.result.get(); }
affected line:
// if error on following line means handler // not meet documented type requirements writehandler. boost_asio_write_handler_check(writehandler, handler) type_check;
it's obvious there's wrong handlers, both of them. can't find out , i'm getting annoyed it.
in first async write, send pointer non static member function without having binded pointer did in second write.
boost::asio::async_write(*s,boost::asio::buffer(&converted_number, sizeof(converted_number)),&client::donothing);
should be
boost::asio::async_write(*s,boost::asio::buffer(&converted_number, sizeof(converted_number)),boost::bind(&client::donothing,this));
Comments
Post a Comment