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_list[type].lock();

} else {

openssl_lock_list[type].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

相关推荐
海拥✘4 小时前
深入理解 IP 地址:概念、分类与日常应用
网络·网络协议·tcp/ip
Miracle&5 小时前
1.TCP/IP模型:各层协议(重点TCP/UDP)
网络协议·tcp/ip·udp
liulilittle6 小时前
IP校验和算法:从网络协议到SIMD深度优化
网络·c++·网络协议·tcp/ip·算法·ip·通信
7ACE6 小时前
Wireshark TS | 接收数据超出接收窗口
网络协议·tcp/ip·wireshark
googleccsdn7 小时前
ESNP LAB 笔记:配置MPLS(Part4)
网络·笔记·网络协议
LUCIAZZZ8 小时前
HTTPS优化简单总结
网络·网络协议·计算机网络·http·https·操作系统
名誉寒冰9 小时前
TCP 拥塞控制与四次挥手解析
网络·网络协议·tcp/ip
Fireplusplus9 小时前
TCP MSS
网络·网络协议·tcp/ip
希赛网9 小时前
华为认证HCIA备考知识点 :IP路由基础(含配置案例)
网络·网络协议·计算机网络·路由交换
青草地溪水旁9 小时前
http response的工作流程详细解析
网络协议·http·应答