0

我使用 django,仅用于下载文件服务器。并使用 curl 在客户端下载文件。当我添加 CURLOPT_RESUME_FROM_LARGE 以恢复中断传输时,错误来了。我不知道这是服务器错误还是客户端错误。
我的客户端下载代码:

    FILE* ptmpfile = fopen((m_download_filepath_pre+tmpfilename).c_str(), "ab+");
    fseek(ptmpfile, 0L, SEEK_END);
    int currentsize = ftell(ptmpfile);

    curl_easy_setopt(curl, CURLOPT_FILE, ptmpfile);
    curl_easy_setopt(curl, CURLOPT_HEADER ,0);
    curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,60);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS ,0);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION ,my_progress_func);
    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA ,sDownload);
    curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, currentsize);

我的服务器错误:

Exception happened during processing of request from ('127.0.0.1', 50232)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/servers/basehttp.py", line 139, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

谢谢~~

已修复:) 客户端错误,CURLOPT_RESUME_FROM_LARGE 必须获取 curl_off_t 参数。

curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)currentsize);

或使用

curl_easy_setopt(curl, CURLOPT_RESUME_FROM, currentsize);

但是谁知道 CURLOPT_RESUME_FROM_LARGE 和 CURLOPT_RESUME_FROM 之间的区别?

4

0 回答 0