本文介绍了初始化SSL和libcurl并获得“内存不足".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用C ++程序使用libcurl和openssl进行https请求.

I intend to do https requests with libcurl and openssl with a C++ program.

我按照文档中的说明用curl_global_init(CURL_GLOBAL_ALL)初始化了libcurl.然后,使用初始化的curl_easy句柄,填充标头和正文,然后将所有内容发送到´ https: //example.com:443/foo ´.它适用于非https连接.

I initialized libcurl with curl_global_init(CURL_GLOBAL_ALL) as described in the documentation. Then I use an curl_easy handle that I initialize, populate with headers and a body, and send everything out to ´https://example.com:443/foo´. It works for non-https connections.

环顾四周,我发现可能已经有其他库在获取SSL上下文,这正是导致libcurl不能正确执行此操作的原因.我收到以下错误消息:

Looking around I find that there may be other libraries that are already getting an SSL context which is what causes libcurl to fail in doing precisely that. I get the following error message:

curl_easy_perform failed: Out of memory

在我的情况下,我使用的是 libmicrohttpd

In my case I am using libmicrohttpd which I initialize with

mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL,
                               htons(port),
                               NULL,
                               NULL,
                               connectionTreat,                     NULL,
                               MHD_OPTION_HTTPS_MEM_KEY,            httpsKey,
                               MHD_OPTION_HTTPS_MEM_CERT,           httpsCertificate,
                               MHD_OPTION_CONNECTION_MEMORY_LIMIT,  memoryLimit,
                               MHD_OPTION_SOCK_ADDR,                (struct sockaddr*) &sad,
                               MHD_OPTION_NOTIFY_COMPLETED,         requestCompleted, NULL,
                               MHD_OPTION_END);

所以我确实在其他地方使用了openSSL.关键是,如果我去掉MHD_USE_SSL部分,就不能解决问题.

So I am indeed using openSSL somewhere else. The thing is, if I take out the MHD_USE_SSL part it does not fix the problem.

这是链接到应用程序的库的列表(我正在使用cmake):

This is the list of libraries that are linked to the application (I'm using cmake):

-lmicrohttpd
-lmongoclient
-lboost_thread
-lboost_filesystem
-lboost_system
-lpthread

是否还有其他可能正在加载SSL的文件?即使我注释掉MHD_USE_SSL标志(以及所有其他相关标志),microhttpd是否仍会加载它?可能还有其他原因导致此错误吗?

Is there any of the others that could be loading SSL? Is microhttpd loading it anyways even if I comment out the MHD_USE_SSL flag (plus all other related flags)? Could there be any other reason for this error?

推荐答案

我不知道libcurl中的任何问题,如果确实存在内存分配函数,该问题将导致返回此错误代码不会失败.在多个模块中使用OpenSSL不会导致这种故障. (我是libcurl的首席开发人员.)

I'm not aware of any problem in libcurl that would cause this error code to get returned if indeed a memory allocation function doesn't fail. Using OpenSSL in multiple modules does not cause such a failure. (I am the lead developer of libcurl.)

因此,在将VERBOSE设置为libcurl或什至是strace的情况下运行您的应用,以查看哪个系统调用失败,它应该为您提供更多线索.

So, run your app with VERBOSE set to libcurl, or even strace to see which syscall that fails and it should give you more clues.

这篇关于初始化SSL和libcurl并获得“内存不足".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 12:15