void chat_client::do_write(const chat_message& msg) { std::shared_ptr<std::string> s = std::make_shared<std::string>(msg.data(), msg.length()); boost::asio::async_write(socket_, boost::asio::buffer(s->c_str(), s->length()), [this, s](boost::system::error_code ec, std::size_t) { if (ec) socket_.close(); }); }
void do_write(const chat_message& msg) { StrPtr s = std::make_shared<std::string>(msg.data(), msg.length()); auto self(shared_from_this()); boost::asio::async_write(socket_, boost::asio::buffer(s->data(), s->length()), [this, self, s](boost::system::error_code ec, std::size_t /*length*/) { if (ec) { room_.leave(shared_from_this()); } }); }