截止日期计时器过期,现在怎么办
deadline timer expires, now what?
我正在查看 asio 示例中的 http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/example/timeouts/async_tcp_client.cpp
以下是我真正难以理解的内容:
- 为什么handle_read又回start_read?
- 计时器过期时会发生什么?我没有看到向计时器提供回调例程。
无效 start_read()
{ 设置读取操作的截止时间。 deadline_.expires_from_now(boost::p osix_time::seconds(30));// Start an asynchronous operation to read a newline-delimited message. boost::asio::async_read_until(socket_, input_buffer_, 'n', boost::bind(&client::handle_read, this, _1));
}
void handle_read(const boost::system::error_code& ec)
{ 如果 (stopped_) 返回;if (!ec) { // Extract the newline-delimited message from the buffer. std::string line; std::istream is(&input_buffer_); std::getline(is, line); // Empty messages are heartbeats and so ignored. if (!line.empty()) { std::cout << "Received: " << line << "n"; } start_read(); } else { std::cout << "Error on receive: " << ec.message() << "n"; stop(); }
}
为什么handle_read又回start_read?
否则,客户端将只读取一次套接字,然后再也不会读取。因此,在成功读取时,客户端希望再次尝试读取。这使得套接字的永久读取。
计时器过期时会发生什么?我没有看到向计时器提供回调例程。
代码位于源文件的顶部:
deadline_.async_wait(boost::bind(&client::check_deadline, this));
如果截止日期已过,check_deadline()
函数将关闭套接字。
相关文章:
- 如果我想在没有更新编译器的情况下使用新功能,该怎么办?
- c++ libCurl :如何使用libCurl接受过期的证书
- 这些老式的演员怎么办?
- 如果参数与数据成员的参数同名,该怎么办?
- MacOS 10.14b / C++使用:找不到命令,该怎么办?
- 我的 cout 上有一个奇怪的输出,它把答案放在第一位,然后在我调用它的地方放一个奇怪的输出.我该怎么办?
- 如果用户输入在整数变量中浮动怎么办?
- 如果我们不创建一个新节点并使用指针插入数据并建立链接(在链表中)怎么办?
- 当两个相等的双精度的相对比较不起作用时,我该怎么办?
- 我需要通过窗口句柄(HWND)获取文件,我该怎么办?
- 如果我必须覆盖非虚拟成员函数怎么办
- 在shared_ptr过期后查找weak_ptr
- 我正在"void value not ignored as it ought to be"我该怎么办?
- 当您的程序在进入主程序之前崩溃时该怎么办?
- 是否可以"unprivate" C++继承中的元素?如果没有怎么办?
- caffe 可以一次接收一批具有不同分辨率的输入吗?如果是这样,怎么办?
- 比率<,> 是恒定的,但如果我想接受不同的比率作为参数怎么办?
- 未定义的引用错误,我该怎么办?
- 如果我忽略返回类型shared_ptr函数的返回值怎么办
- 截止日期计时器过期,现在怎么办