3.4 断点续传实例//采用CURLOPT_RESUME_FROM_LARGE实现文件断点续传功能#include#include#include#include//这个函数为CURLOPT_HEADERFUNCTION参数构造/*从http头部获取文件size*/size_tgetcontentlengthfunc(void*ptr,size_tsize,size_tnmemb,void*stream){intr;longlen=0;/*_snscanf()isWin32specific*///r=_snscanf(ptr,size*nmemb,"Content-Length:%ld\n",&len);r=sscanf(ptr,"Content-Length:%ld\n",&len);if(r)/*Microsoft:wedon'treadthespecs*/*((long*)stream)=len;returnsize*nmemb;}/*保存下载文件*/size_twirtefunc(void*ptr,size_tsize,size_tnmemb,void*stream){returnfwrite(ptr,size,nmemb,stream);}/*读取上传文件*/size_treadfunc(void*ptr,size_tsize,size_tnmemb,void*stream){FILE*f=stream;size_tn;if(ferror(f))returnCURL_READFUNC_ABORT;n=fread(ptr,size,nmemb,f)*size;returnn;}//下载 或者上传文件函数intdownload(CURL*curlhandle,constchar*remotepath,constchar*localpath,longtimeout,longtries){FILE*f;curl_off_tlocal_file_len=-1;longfilesize=0;CURLcoder=CURLE_GOT_NOTHING;intc;structstatfile_info;intuse_resume=0;/*得到本地文件大小 *///if(access(localpath,F_OK)==0)if(stat(localpath,&file_info)==0){local_file_len=file_info.st_size;use_resume=1;}//采用追加方式打开文件,便于实现文件断点续传工作f=fopen(localpath,"ab+");if(f==NULL){perror(NULL);return0;}//curl_easy_setopt(curlhandle,CURLOPT_UPLOAD,1L);curl_easy_setopt(curlhandle,CURLOPT_URL,remotepath);curl_easy_setopt(curlhandle,CURLOPT_CONNECTTIMEOUT,timeout);//设置连接超时,单位秒//设置 http头部处理函数curl_easy_setopt(curlhandle,CURLOPT_HEADERFUNCTION,getcontentlengthfunc);curl_easy_setopt(curlhandle,CURLOPT_HEADERDATA,&filesize);//设置文件续传的位置给 libcurlcurl_easy_setopt(curlhandle,CURLOPT_RESUME_FROM_LARGE,use_resume?local_file_len:0);curl_easy_setopt(curlhandle,CURLOPT_WRITEDATA,f);curl_easy_setopt(curlhandle,CURLOPT_WRITEFUNCTION,wirtefunc);//curl_easy_setopt(curlhandle,CURLOPT_READFUNCTION,readfunc);//curl_easy_setopt(curlhandle,CURLOPT_READDATA,f);curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1L...