Curl多线程https访问,崩溃问题修复

Curl: ��: SSL and multithread crash on windows, how to use mutex on windows?

SSL and multithread crash on windows, how to use mutex on windows?

From: mao mao <lmjrd_at_hotmail.com>

Date: Fri, 25 Nov 2016 09:50:48 +0000

Thankyou Thomas and Johan both

to Johan: how to use these two functions

openssl_crypto_locking_callback

openssl_crypto_init_locks

when start new thread using _beginthreadex or createthread or afxbeginthread?

Using boost:

#include <boost/ptr_container/ptr_vector.hpp>

#include <openssl/crypto.h>

#define OPENSSL_THREAD_DEFINES

#include <openssl/opensslconf.h>

#if !defined(OPENSSL_THREADS)

#error OpenSSL needs to be compiled with thread support

#endif

boost::ptr_vector<boost::mutex> openssl_lock_list;

void openssl_crypto_locking_callback(

int mode, int type, const char * const, int

) {

if( mode & CRYPTO_LOCK ) {

openssl_lock_listtype.lock();

} else {

openssl_lock_listtype.unlock();

}

}

void openssl_crypto_init_locks()

{

for(int i = 0; i < CRYPTO_num_locks(); ++i) {

openssl_lock_list.push_back(new boost::mutex());

}

// Not neccessary according to docs, and boost can't really give a pointer or

// integer ID of a thread

// CRYPTO_THREADID_set_callback(openssl_crypto_threadid_callback);

CRYPTO_set_locking_callback(openssl_crypto_locking_callback);

}

Johan de Vries

Software Developer

[http://www.ixon.net/wp-content/uploads/2013/12/logo-default.png](http://www.ixon.net/wp-content/uploads/2013/12/logo-default.png "http://www.ixon.net/wp-content/uploads/2013/12/logo-default.png")

> SSL and multithread crash on windows, how to use mutex on windows?

Best way is you post a striped down example which crashes.

For me the following works, without a problem.

Once:

curl_global_init(CURL_GLOBAL_DEFAULT);

For each thread:

_beginthread(...);

share = curl_share_init();

curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);

curl = curl_easy_init();

curl_easy_setopt(curl, CURLOPT_SHARE, share);

curl_easy_setopt(curl, CURLOPT_URL, "https://google.com");

curl_easy_perform(curl);

curl_easy_cleanup(curl);

Cheers,

Thomas


List admin: https://cool.haxx.se/list/listinfo/curl-library

Etiquette: curl - Mailing List Etiquette


List admin: https://cool.haxx.se/list/listinfo/curl-library

Etiquette: curl - Mailing List Etiquette

Received on 2016-11-25

相关推荐
企业通信技术笔记5 小时前
企业IM内外网隔离部署:DNS、证书、WebSocket与跨网接口设计
websocket·网络协议·架构·php·信息与通信
流烟默7 小时前
HTTP 连接管理技术梳理:JDK KeepAliveCache 机制与池化选型
java·网络协议·http
Java小白笔记7 小时前
FlClash TUN 栈模式选择与验证指南
网络·网络协议
清水白石0088 小时前
ThreadPoolExecutor 线程越多越快?从 30ms HTTP 调用讲透并发数、连接池与背压
网络·网络协议·http
IT小白杨8 小时前
eBay多账号如何应对关联判定:主体、收款、IP、环境四层配置清单一次讲清
java·网络·网络协议·tcp/ip·自动化·指纹浏览器
隐擎fox10 小时前
网络传输安全剖析:WebRTC 本地真实 IP 泄漏机制(STUN/TURN)与 Python 防护检测实战
网络·网络协议·tcp/ip·安全·webrtc
为思念酝酿的痛10 小时前
应用层协议HTTP
网络·网络协议·http
薛之谦_12 小时前
国际SSL证书与国密SSL证书:专业视角下的全面解读
网络·网络协议·ssl
Wang's Blog1 天前
Java框架快速入门: Spring Security+OAuth2之HTTP请求结构与认证基础
java·spring·http
Zenova EdgeOS1 天前
C++ 工业边缘 libcurl HTTP 客户端实战
开发语言·c++·网络协议·边缘计算