curl学习(一):段错误
2016-06-13 18:33
477 查看
c语言使用curl时出现段错误
问题发现在使用c语言编程时,按照一般流程使用curl进行http数据的获取,没有错误,但是当开启线程调用该函数频繁时,会出现段错误,并且复现起来较为困难,经后期排查,发现问题出现在了curl上面,处理完该bug后,稍加整理,作为以后提醒
原因
原来libcurl在configure默认配置编译的情况下,它是使用alarm+siglongjmp实现域名解析超时。当多个线程都使用超时处理的时候,同时主线程中有sleep或是wait等操作。libcurl将会发信号打断这个wait从而导致程序退出
解决方法
*在设置curl属性时添加一条
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
这样域名解析就没了超时机制*
官网说明
**`CURLOPT_NOSIGNAL
Pass a long. If it is 1, libcurl will not use any functions that install
signal handlers or any functions that cause signals to be sent to
unix applications to still set/use all timeout options etc, without
risking getting signals. (Added in 7.10)
If this option is set and libcurl has been built with the standard
name resolver, timeouts will not occur while the name resolve
takes place. Consider building libcurl with c-ares support to enable
asynchronous DNS lookups, which enables nice timeouts for name
resolves without signals.
Setting CURLOPT_NOSIGNAL to 1 makes libcurl NOT ask the
system to ignore SIGPIPE signals, which otherwise are sent by the
system when trying to send data to a socket which is closed in the
other end. libcurl makes an effort to never cause such SIGPIPEs to
trigger, but some operating systems have no way to avoid them
and even on those that have there are some corner cases when
they may still happen, contrary to our desire. In addition, using
CURLAUTH_NTLM_WB authentication could cause a SIGCHLD
signal to be raised.`**
参考链接
http://www.xuebuyuan.com/126531.html
相关文章推荐
- SourceProvider.getJniDirectories
- 如何组织构建多文件 C 语言程序(二)
- Trac 中文语言安装
- 如何写好 C main 函数
- 软件 bug 的生命周期
- Firefox2中输入框丢失光标bug的解决方法
- for命令的一些bug分析
- Lua和C语言的交互详解
- 修正IE下使用CSS属性overflow的bug
- 解决IE6 3像素Bug的css写法
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解
- C语言内存对齐实例详解
- C语言编程中统计输入的行数以及单词个数的方法
- C语言自动生成enum值和名字映射代码
- C语言练习题:自由落体的小球简单实例
- 使用C语言判断英文字符大小写的方法