使用Boost :: Log记录套接字通信

时间:2017-02-20 23:33:37

标签: c++ boost-asio boost-log

我希望通过tcp代理服务器异步记录在客户端和服务器之间流动的套接字数据。

我无法找到有关点击缓冲区并写入日志接收器的详细信息。有什么帮助吗?

以下是我能够成功使用/执行的Boost:ASIO代码 -

  void handle_upstream_connect(const boost::system::error_code& error)
  {
     if (!error)
     {
        upstream_socket_.async_read_some(
             boost::asio::buffer(upstream_data_,max_data_length),
             boost::bind(&bridge::handle_upstream_read,
                  shared_from_this(),
                  boost::asio::placeholders::error,
                  boost::asio::placeholders::bytes_transferred));

        downstream_socket_.async_read_some(
             boost::asio::buffer(downstream_data_,max_data_length),
             boost::bind(&bridge::handle_downstream_read,
                  shared_from_this(),
                  boost::asio::placeholders::error,
                  boost::asio::placeholders::bytes_transferred));
     }
     else
        close();
  }

私人:

  void handle_downstream_write(const boost::system::error_code& error)
  {
     if (!error)
     {
        upstream_socket_.async_read_some(
             boost::asio::buffer(upstream_data_,max_data_length),
             boost::bind(&bridge::handle_upstream_read,
                  shared_from_this(),
                  boost::asio::placeholders::error,
                  boost::asio::placeholders::bytes_transferred));
     }
     else
        close();
  }

  void handle_downstream_read(const boost::system::error_code& error,
                              const size_t& bytes_transferred)
  {
     if (!error)
     {
        async_write(upstream_socket_,
              boost::asio::buffer(downstream_data_,bytes_transferred),
              boost::bind(&bridge::handle_upstream_write,
                    shared_from_this(),
                    boost::asio::placeholders::error));
     }
     else
        close();
  }

  void handle_upstream_write(const boost::system::error_code& error)
  {
     if (!error)
     {
        downstream_socket_.async_read_some(
             boost::asio::buffer(downstream_data_,max_data_length),
             boost::bind(&bridge::handle_downstream_read,
                  shared_from_this(),
                  boost::asio::placeholders::error,
                  boost::asio::placeholders::bytes_transferred));
     }
     else
        close();
  }

  void handle_upstream_read(const boost::system::error_code& error,
                            const size_t& bytes_transferred)
  {
     if (!error)
     {
        async_write(downstream_socket_,
             boost::asio::buffer(upstream_data_,bytes_transferred),
             boost::bind(&bridge::handle_downstream_write,
                  shared_from_this(),
                  boost::asio::placeholders::error));
     }
     else
        close();
  }

0 个答案:

没有答案