Crow:run的流程5 do_read接收并处理http请求

class Connection
{
private:
    void do_read()
    {
        is_reading = true;
        adaptor_.socket().async_read_some(
          asio::buffer(buffer_),
          [this](const asio::error_code& ec, std::size_t bytes_transferred) {
              bool error_while_reading = true;
              if (!ec)
              {
                  bool ret = parser_.feed(buffer_.data(), bytes_transferred);
                  if (ret && adaptor_.is_open())
                  {
                      error_while_reading = false;
                  }
              }
              ...
        });
    }
    std::array buffer_;
};

do_read通过async_read_some接收并保持数据到buffer_中

然后会通过parser_.feed分析接收到的数据

struct HTTPParser : public http_parser
{
    bool feed(const char* buffer, int length)
    {
        if (message_complete)
            return tru

你可能感兴趣的:(Crow,c++)