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

相关推荐
Predestination王瀞潞16 小时前
5.4.2 通信->WWW万维网内容访问标准(W3C):WWW(World Wide Web) 核心技术规范
网络·网络协议·https·www
虾..16 小时前
TCP协议
网络·网络协议·tcp/ip
上去我就QWER16 小时前
详解HTTP协议中的multipart/form-data
网络·网络协议·http
Predestination王瀞潞19 小时前
5.3.2 通信->HTTP3超文本传输协议标准(IETF RFC 9114):Headers 请求头 响应头
网络·网络协议·tcp/ip
sugar__salt19 小时前
网络原理(五)——HTTP
网络·网络协议·http
夜泉_ly20 小时前
泉面 TOP150 -TCP 和 UDP 的区别?
网络协议·tcp/ip·udp
特立独行的猫a20 小时前
ESP32小智AI的WebSocket 调试工具实现,小智AI后台交互过程揭秘(一、开篇介绍 )
人工智能·websocket·网络协议·esp32·小智ai
Predestination王瀞潞20 小时前
5.4.1 通信->WWW万维网内容访问标准(W3C):WWW(World Wide Web)基本信息&核心设计目标&现实意义
css·网络·网络协议·html·url·www
taxunjishu21 小时前
Profinet转Modbus TCP柔性制造工业自动化集成方案
网络协议·自动化·制造
芒果披萨21 小时前
http请求
网络·网络协议·http