Skip to content

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

@Eggache666

Description

@Eggache666

我在之前一个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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions