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

相关推荐
乾元几秒前
红队 / 蓝队:用 AI 自动生成攻击场景并评估防御效果——从“安全演练”到“可计算的网络对抗系统”
运维·网络·人工智能·网络协议·安全·web安全·架构
德迅云安全—珍珍11 小时前
什么是udp攻击,为什么udp攻击难防御
网络·网络协议·udp
talenteddriver14 小时前
web: http请求(自用总结)
前端·网络协议·http
乾元15 小时前
AI 驱动的入侵检测与异常会话判别:从规则到行为分析前言:从“捕获敌人”到“守卫秩序”
运维·网络·人工智能·网络协议·安全
文弱书生65615 小时前
4-electronbot-USB协议前置知识
网络协议
LCG米16 小时前
车载以太网SOME/IP协议栈在TI TDA4VM平台上的实现与测试
网络·网络协议·tcp/ip
chalmers_1518 小时前
将单个 WebSocket 客户端封装为实例
服务器·websocket·网络协议
ZeroNews内网穿透19 小时前
EasyNode 结合 ZeroNews,实现远程管理服务器
运维·服务器·网络协议·安全·http
00后程序员张20 小时前
AppStoreInfo.plist 在苹果上架流程中的生成方式和作用
android·小程序·https·uni-app·iphone·webview
IT 行者1 天前
Spring Boot 4 升级指南:告别RestTemplate,拥抱现代HTTP客户端
spring boot·后端·http