使用 libcurl C/C++ 下载时冻结
我正在开发下载文件并通过 SDL 窗口显示传输速度的软件。 我的问题是,当我启动下载时,该窗口立即被 Windows 识别为崩溃的程序。下载完成后一切就OK了。 我的程序没有崩溃,我认为这是因为它在下载时无法响应。 有什么想法如何解决这个问题吗?
PS:执行时“崩溃”的代码示例:
curl_easy_setopt(curl, CURLOPT_URL, valeurs->URL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, downloadData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
I'm working on software which downloads a file and shows transfer speed via an SDL window.
My problem is that when I launch a download, the window is immediately identified by windows as a crashed program. As soon as the download is completed, everything is okay.
My program didn't crash and I think that it's because it can't respond when it's downloading.
Any ideas how to solve that?
PS: example of code which 'crashes' when performed:
curl_easy_setopt(curl, CURLOPT_URL, valeurs->URL);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, downloadData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了防止这些冻结,您需要在主线程中放置一个事件管理器(SDL_PoolEvent + SDL_Delay,以免过度使用 CPU)
To prevent those freeze, you need to put, in the main thread an event manager (SDL_PoolEvent + SDL_Delay to not overuse CPU)