c++ - asio::async_write SEG FAULT -
i not sure why getting segmentation fault when begin async_write() string buffer. have used function in past.
here method segmentation fault:
void stringsocket::sendline(const string& towrite) { try { std::cout << "in stringsocket::sendline()\n"; std::cout << "is socket alive?: " << (bool)s->is_open() << "\n"; std::cout << "towrite: " << towrite; //s = asio::ip::tcp::socket* asio::async_write(*this->s, asio::buffer(towrite), boost::bind(&stringsocket::messagesent, this, asio::placeholders::error)); std::cout << "after: asio::async_write()\n"; } catch (int e) { std::cout << "error: " << e << "\n"; } } here compiler says:
in main() in servertcp::servertcp()! in spreadsheet::spreadsheet() in servertcp::start_accept()! in client::client(asio::io_service& io_service, std::string name) in stringsocket::stringsocket(asio::ip::tcp::socket *_socket) in client::getsocket() in stringsocket::undersoc() in servertcp::pickspreadsheet()! in client::getclientname() in client::sendtogui(std::string mess) in stringsocket::beginsend(const string& towrite, sendcallback callback, void* payload) towrite: welcome ss! user: user0000 in stringsocket::processsend() texttosend: welcome ss! user: user0000 in stringsocket::sendline() socket alive?: 1 towrite: welcome ss! user: user0000 segmentation fault
if check reference async_write (all overloads says same on subject) tell handler function takes 2 arguments, first error code , length of sent data.
your boost::bind call provides one argument. still have tell boost::bind there argument filled in later. placeholder argument, boost::asio::placeholders::bytes_transferred:
so change e.g.
boost::bind(&stringsocket::messagesent, this, asio::placeholders::error, asio::placeholders::bytes_transferred)
Comments
Post a Comment