20 Mart 2018 Salı

beast async_read metodu

Örnek
Şöyle yaparız.
using tcp = boost::asio::ip::tcp;    // from <boost/asio/ip/tcp.hpp>
namespace ssl = boost::asio::ssl;    // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>

class session : public std::enable_shared_from_this<session>
{
    ssl::stream<tcp::socket> stream_;
    boost::beast::flat_buffer buffer_; // (Must persist between reads)
    http::response<http::string_body> res_;

public:
  void on_write(boost::system::error_code ec,std::size_t bytes_transferred)
  {
    boost::ignore_unused(bytes_transferred);

    if(ec)
      return fail(ec, "write");

    // Receive the HTTP response
    http::async_read(stream_, buffer_, res_,
      std::bind(
        &session::on_read,
        shared_from_this(),
        std::placeholders::_1,
        std::placeholders::_2));
  }

  void on_read(boost::system::error_code ec,std::size_t bytes_transferred)
  {
    ...
  }
  
};

Hiç yorum yok:

Yorum Gönder