コード例 #1
0
ファイル: ChatClient.cpp プロジェクト: kuzminskaya/hpcourse
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();
	});
}
コード例 #2
0
ファイル: chat_server.cpp プロジェクト: Gremory/hpcourse
  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());
          }
        });
  }
コード例 #3
0
ファイル: chat_client.cpp プロジェクト: mw-ding/DMW-Chat
 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();
     }
 }
コード例 #4
0
ファイル: chat_client.cpp プロジェクト: mw-ding/DMW-Chat
 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));
     }
 }