void handle_connect(const boost::system::error_code &error) { if (!error) { boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(), chat_message::header_length), boost::bind(&chat_client::handle_read_header, this, boost::asio::placeholders::error)); } }
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()); } }); }
void handle_read_header(const boost::system::error_code &error) { if (!error) { std::cout.write(read_msg_.body(), read_msg_.body_length()); std::cout << std::endl; boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(), chat_message::header_length), boost::bind(&chat_client::handle_read_header, this, boost::asio::placeholders::error)); } else { do_close(); } }