简体   繁体   English

boost :: asio :: async_read_until的处理程序何时调用?

[英]when is the handler for boost::asio::async_read_until invoked?

I'm a novice at boost. 我是新手。

I'm testing boost async client. 我正在测试Boost异步客户端。 the reference code is as below. 参考代码如下。

http://think-async.com/Asio/boost_asio_1_5_3/doc/html/boost_asio/example/http/client/async_client.cpp http://think-async.com/Asio/boost_asio_1_5_3/doc/html/boost_asio/example/http/client/async_client.cpp

the code is well done if "Connection: close" header value exists. 如果"Connection: close"标头值存在,则代码编写正确。 but, "handle_read_status_line" handler was never invoked when I omitted "Conneciton: close" header in the HTTP request. 但是,当我在HTTP请求中省略"Conneciton: close"标头时,从未调用过"handle_read_status_line"处理程序。 (all handler for receiving HTTP response are invoked only when TCP connection is closed.) (仅当TCP连接关闭时,才会调用所有用于接收HTTP响应的处理程序。)

In my opinion, "handle_read_status_line" should be invoked because HTTP response always include "\\\\r\\\\n" regardless of "Connection" header. 我认为,应该调用"handle_read_status_line"因为HTTP响应始终包括"\\\\r\\\\n"而与"Connection"标头无关。

Could anybody explain to me when the handler for async_read_until is invoked? 有人可以向我解释何时调用async_read_until的处理程序吗?

Thanks in advance. 提前致谢。

In general, async_read_until returns when the MatchCondition has been met. 通常,当满足MatchCondition时, async_read_until返回。

The sample assumes that the connection is per-request. 该示例假定该连接是每个请求的。 It's pretty explicit in that: 这很明显:

  // Start reading remaining data until EOF.
  boost::asio::async_read(socket_, response_,
      boost::asio::transfer_at_least(1),
      boost::bind(&client::handle_read_content, this,
        boost::asio::placeholders::error));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM