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]

> 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

相关推荐
Zfox_3 小时前
HTTP cookie 与 session
linux·服务器·网络·c++·网络协议·http
qq_3927944810 小时前
为什么 TCP 挥手需要有 TIME_WAIT 状态?
网络·网络协议·tcp/ip
闲猫11 小时前
正向代理(动态 IP 代理)和反向代理
网络·网络协议·tcp/ip
小徐同学14181 天前
BGP边界网关协议(Border Gateway Protocol)路由聚合详解
运维·服务器·网络·网络协议·信息与通信·bgp
sumatch1 天前
RPC是什么?和HTTP区别?
网络协议·http·rpc
Ljw...1 天前
TCP协议(网络)
网络·网络协议·tcp/ip·tcp·tcp协议
ke_wu2 天前
使用select函数创建多线程TCP服务端
网络·网络协议·tcp/ip
zzyh1234562 天前
tcp/ip协议通俗理解,tcpip协议通俗理解
网络·网络协议·tcp/ip
路由侠内网穿透2 天前
无公网IP 外网访问媒体服务器 Emby
服务器·网络协议·tcp/ip·docker·媒体
雨中rain2 天前
Linux -- HTTP 请求 与 响应 报文
网络·网络协议·http