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

相关推荐
SQingL6 分钟前
解决SSLError: [SSL: DECRYPTION_FAILED_OR_BAD_RECORD_MAC] decryption faile的问题
服务器·网络协议·ssl
JhonKI1 小时前
【Linux网络】构建与优化HTTP请求处理 - HttpRequest从理解到实现
linux·网络·http
网工养成记_121383 小时前
路由协议基础
网络·网络协议·智能路由器
JhonKI3 小时前
【Linux网络】Http服务优化 - 增加请求后缀、状态码描述、重定向、自动跳转及注册多功能服务
linux·网络·http
茉莉玫瑰花茶4 小时前
socket套接字-UDP(中)
网络·网络协议·udp
iOS开发上架哦5 小时前
charles网络抓包入门教程
网络协议·安全
喝养乐多长不高6 小时前
详细PostMan的安装和基本使用方法
java·服务器·前端·网络协议·测试工具·https·postman
薯条不要番茄酱7 小时前
【网络原理】从零开始深入理解TCP的各项特性和机制.(三)
网络·网络协议·tcp/ip
专注API从业者8 小时前
反爬策略应对指南:淘宝 API 商品数据采集的 IP 代理与请求伪装技术
网络·网络协议·tcp/ip
老六ip加速器17 小时前
如何获取静态IP地址?完整教程
网络·网络协议·tcp/ip