Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何正确设置超时?或者说正确关闭http_stream?http_stream的async_open似乎也是同步的。 #53

Open
Eggache666 opened this issue Jan 9, 2020 · 0 comments

Comments

@Eggache666
Copy link

我在之前一个issue中提出了超时问题,回答的是multi_download接口中设置超时,我想知道http_stream如何正确设置。

           // 以下面一个链接完全打开较慢为例,或者有的链接等待很长时间,而http_stream无法设置超时断开,我用异步定时器设置超时断开,但是却一直在下载中。这个async_open似乎在同步执行中,请教如何正确关闭这种完全打开很慢或者说卡死了的链接?

	std::string url = "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.zip";

	boost::asio::io_service ios;

	boost::asio::deadline_timer timer(ios);
	avhttp::http_stream h(ios);

	timer.expires_from_now(boost::posix_time::seconds(5));
	timer.async_wait([&](const boost::system::error_code& ec) {
		std::cout << "cancel\n";
		h.close();
		});

	h.check_certificate(false);
	h.async_open(url, [&](const boost::system::error_code& ec) {
		if (!ec)
		{
			std::cout << "openning...\n";
			std::ofstream("boost.zip", std::ios::binary) << &h;
			h.close();
			timer.cancel();
		}
		});

	ios.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant