Recently used curl. When multiple threads are enabled for simultaneous download and timeout is set, the program randomly reports the following errors.
(GDB) BT
#0 0x00002ac0a97a2ec2 in ?? () From/usr/lib64/libcurl. so.3
#1 0x00002ac0a97a37dd in ?? () From/usr/lib64/libcurl. so.3
#2 0x00002ac0a97a4755 in curl_mvsnprintf () from/usr/lib64/libcurl. so.3
#3 0x00002ac0a97a3083 in curl_msnprintf () from/usr/lib64/libcurl. so.3
#4 0x00002ac0a9793ecb in curl_failf () from/usr/lib64/libcurl. so.3
#5 0x00002ac0a978cf03 in curl_resolv () from/usr/lib64/libcurl. so.3
#6 0x000000004c22197d in ?? ()
#7 0x0000000000000000 in ?? ()
After checking the official curl documents, the following explanations are provided:
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 the process. this option is mainly here to allow multi-threaded 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_wbauthentication
Cocould cause a sigchld signal to be raised.
It means:
That is, when multiple threads use timeout processing, sleep or wait operations are performed in the main thread. If this option is not set, libcurl will send a signal to interrupt the wait and cause the program to exit.
Therefore, you can set this option to 1.
Curl_easy_setopt (curl, curlopt_nosignal, 1l );
Address: http://blog.csdn.net/niehanzi/article/details/7365913