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

news/2025/2/19 12:35:41/

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]



> 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


http://www.ppmy.cn/news/1277060.html

相关文章

apache poi_5.2.5 实现对表格单元格的自定义变量名进行图片替换

apache poi_5.2.5 实现对表格单元格的自定义变量名进行图片替换 实现思路 1.首先定位到自定义变量名 2.然后先清除自定义变量名&#xff0c;可利用setText(null,0)来清除 3.在自定义变量名的位置添加图片&#xff0c;使用下面的代码 4.对于图片布局有要求的&#xff0c;利用C…

大模型三级跳:2023年AI行业的崭新篇章

2023年&#xff0c;大模型的发展如同一场三级跳&#xff0c;迅速跃升至新的高度。从ChatGPT的火爆&#xff0c;到众多大厂纷纷入场&#xff0c;再到百模大战的激烈角逐&#xff0c;这一年的AI行业充满了竞争与变革。 首先&#xff0c;大模型的崛起标志着AI技术进入了一个新的阶…

【csapp】bufferlab

文章目录 实验要求实验内容Level 0Level 1Level 2Level 3Level 4 实验要求 Level 0 test 运行完后&#xff0c;不直接返回退出&#xff0c;而是跳到smoke函数处&#xff0c;继续运行&#xff0c;当 smoke 运行完毕后退出Level 1 在 Level 0 的基础上&#xff0c;使 getbuf 函数…

solidity 重入漏洞

目录 1. 重入漏洞的原理 2. 重入漏洞的场景 2.1 msg.sender.call 转账 2.2 修饰器中调用地址可控的函数 1. 重入漏洞的原理 重入漏洞产生的条件&#xff1a; 合约之间可以进行相互间的外部调用 恶意合约 B 调用了合约 A 中的 public funcA 函数&#xff0c;在函数 funcA…

Linux基础第一章:基础知识和基础命令(1)

目录 一.虚拟机网络-网卡的三种连接方式 二.Linux基础知识 1.linux的哲学思想 2.分区 3.命令行头解释 4.根目录下的常见文件 bin dev proc boot etc tmp var mnt opt home lib lib64 usr 5.shell 6.命令基础 内部命令 命令执行的过程 命令行格式 命令 …

sklearn和tensorflow的理解

人工智能的实现是基于机器学习&#xff0c;机器学习的一个方法是神经网络&#xff0c;以及各种机器学习算法库。 有监督学习&#xff1a;一般数据构成是【特征值目标值】 无监督学习&#xff1a;一般数据构成是【特征值】 Scikit-learn(sklearn)的定位是通用机器学习库&…

ChatGPT如何计算token数?

GPT 不是适用于某一门语言的大型语言模型&#xff0c;它适用于几乎所有流行的自然语言。所以 GPT 的 token 需要 兼容 几乎人类的所有自然语言&#xff0c;那意味着 GPT 有一个非常全的 token 词汇表&#xff0c;它能表达出所有人类的自然语言。如何实现这个目的呢&#xff1f;…

命令执行 [SWPUCTF 2021 新生赛]babyrce

打开题目 我们看到题目说cookie值admin等于1时&#xff0c;才能包含文件 bp修改一下得到 访问rasalghul.php&#xff0c;得到 题目说如果我们get传入一个url且不为空值&#xff0c;就将我们get姿势传入的url的值赋值给ip 然后用正则过滤了 / /&#xff0c;如果ip的值没有 / …