【问题标题】:libcurl + openssl cannot download files bigger than 2GBlibcurl + openssl 无法下载大于 2GB 的文件
【发布时间】:2013-02-19 20:45:01
【问题描述】:

我正在尝试使用 libcurl 7.20.0 和 openssl 0.9.8l 下载文件(但我将库更新为 7.29.0 和 1.0.1e),Windows 7 并且一切都在为 amd64 编译以下载大文件.我使用 curlpp 作为 curl 的包装器。问题是,一旦达到 2GB,下载就会停止并出现错误Failed writing body (0 != 8999)。我用来做请求的代码是:

boost::shared_ptr<curlpp::Easy> curl_request(boost::make_shared<curlpp::Easy>());
curl_request.setOpt(new curlpp::options::HttpVersion(CURL_HTTP_VERSION_1_0));
curl_request.setOpt(new curlpp::options::Timeout(3600));
curl_request.setOpt(new curlpp::options::SslVerifyHost(0));
curl_request.setOpt(new curlpp::options::SslVerifyPeer(0));
curl_request->setOpt(new curlpp::options::Url(request_uri));
if (cookies.size() == 0) {
    curl_request->setOpt(new curlpp::options::CookieList("dummy"));
} else {
    BOOST_FOREACH(const std::string &cookie, m_cookies) {
        curl_request->setOpt(new curlpp::options::CookieList(cookie));
    }
}
curl_request->setOpt(new curlpp::options::Post(true));
curl_request->setOpt(new curlpp::options::PostFields(query_string));
curl_request->setOpt(new curlpp::options::WriteStream(stream.get()));

try {
    curl_request->perform();
} catch (std::exception &ex) {
    error = true;
    std::cerr << "caught Unknown error: " << ex.what() << std::endl;
}

编辑流是字符串流,我使用的是 MS VS 2008

【问题讨论】:

  • 什么操作系统?是 32 位还是 64 位?
  • 您是否将 CURLOPT_VERBOSE 和 CURLOPT_HEADER 设置为 1 以查看实际从服务器返回的内容? 2GB 限制似乎非常熟悉作为 HTTP 特定问题(早在 1990 年代,很多文件系统都有 2GB 限制,所以我认为人们认为这是一个可以接受的限制)。

标签: c++ curl openssl libcurl


【解决方案1】:

这不是 libcurl 或 OpenSSL 限制。这可能是您的文件系统(FAT?)或 WriteStream 实现(或类似的)阻止了它的工作。

错误消息似乎暗示突然写入磁盘失败,这可能是写入溢出了最大支持大小。

【讨论】:

  • 很可能是这样。我正在写一个字符串流。
  • 所以,在 2gb 之后写入字符串流时出现问题。我换了一个ofstream,一切正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-19
  • 1970-01-01
相关资源
最近更新 更多