小编jef*_*RTC的帖子

将 shared_ptr 用于 private_key 时出现分段错误

更新

[X] 我发现TLS::credentials creds在全局范围内声明时会发生这种情况,但是如果我在外部声明它不会发生段错误。

我需要它是全局的,因为它有助于缓存证书,并且多个线程可以使用其他线程创建的证书,而无需花时间创建新证书。

[X] 我进一步减少了大约 200 行的代码。到 100 行

我正在使用 Botan 创建一个 TLS 应用程序,我的应用程序在应用程序结束时因段错误而崩溃。

我试图用 Valgrind 调试它,但它无济于事。

这是来自 Valgrind 的堆栈跟踪,

==3841967== Invalid write of size 8
==3841967==    at 0x4842964: memset (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==3841967==    by 0x566A82F: Botan::deallocate_memory(void*, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libbotan-2.so.12.12.1)
==3841967==    by 0x55E1A4D: ??? (in /usr/lib/x86_64-linux-gnu/libbotan-2.so.12.12.1)
==3841967==    by 0x40EC7B: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:155)
==3841967==    by 0x40EC29: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:730)
==3841967==    by 0x41112D: std::__shared_ptr<Botan::RSA_Public_Data const, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:1169)
==3841967==    by 0x411107: std::shared_ptr<Botan::RSA_Public_Data const>::~shared_ptr() (shared_ptr.h:103)
==3841967==    by 0x41109D: Botan::RSA_PublicKey::~RSA_PublicKey() (rsa.h:25) …
Run Code Online (Sandbox Code Playgroud)

c++ shared-ptr segmentation-fault botan c++11

49
推荐指数
2
解决办法
2618
查看次数

Sendgrid 的自动安全性如何运作?

SendGrid 的自动化安全性通过 CNAME 记录自动执行 SPF 和 DKIM。它甚至允许直接使用域名注册商拥有我们自己的 SPF 和 DKIM 记录。

他们如何做到这一点而不与现有 SPF 和 DKIM 记录串通代替域?

spf dkim sendgrid

12
推荐指数
1
解决办法
2489
查看次数

Promise.allSettled 永远卡住

我过去Promise.allSettled常常以批量方式获取网站。如果我将网站列表的大小限制为 ,它工作得很好10,但一旦我将其增加到 ,它就会卡住1000

这很奇怪,从来没有发生在我身上。我等了三天,直到脚本完成,但它仍然停留在第一个1000项目上。

const rp = require('request-promise');
const lineReader = require('line-by-line');

const reader = new lineReader("./all.json");

let lines = [];
const limit = 1000;

let successCount = 0;

reader.on('line', async (line) => {
    line = JSON.parse(line);

    lines.push(line);

    if (lines.length === limit) {
        reader.pause();

        let promises = [];

        for (const line of lines) {
            promises.push(rp(line.website))
        }
    
        await Promise.allSettled(promises);

        successCount++
        console.log(`Success Count is ${successCount}`);

        lines = [];

        reader.resume();
    }
});
Run Code Online (Sandbox Code Playgroud)

data.json文件具有以下格式的网站列表, …

javascript

5
推荐指数
1
解决办法
1483
查看次数

C++20 概念的用例是什么?

我在回顾 C++20 特性时发现了概念。我发现他们向模板参数添加了验证,但除此之外,我不明白 C++20 概念的真实用例是什么。

C++ 已经有类似的东西std::is_integral,它们可以很好地执行验证。

我确定我遗漏了一些关于 C++20 概念及其支持的内容。

c++ c++-concepts c++20

4
推荐指数
1
解决办法
141
查看次数

为什么在函数内部使用thread_local?

我认为如果函数不修改非本地数据,那么它们就是线程安全的。

根据这个答案我的假设是正确的。但是,最近我遇到了这段代码,

int intRand(const int & min, const int & max) {
    static thread_local std::mt19937 generator;
    std::uniform_int_distribution<int> distribution(min,max);
    return distribution(generator);
}
Run Code Online (Sandbox Code Playgroud)

这段代码让我很困惑。thread_local如果函数已经是线程安全的,为什么还要使用它?

c++

2
推荐指数
1
解决办法
408
查看次数

为什么 Promise.race 完成后 Node.js 不退出?

在 Node.js 中,我使用Promise.race超时和取消 Request-Promise 库发出的请求。我的Promise.race实现似乎阻止了该程序。

Promise.race确实解析并返回,但此后程序永远不会退出。

再次,我想强调等待确实完成并记录响应,但程序永远不会退出。

const rp = require('request-promise');

/**
 * @param {rp.RequestPromise} request 
 * @param {Number} ms 
 * @returns {Error}
 */
const delay = (request, ms) => new Promise((resolve, reject) => setTimeout(() => {
    request.cancel();
    return reject(new Error("Timeout"))
}, ms))

async function main() {
    try {
        const options = {
            method: 'GET',
            url: "https://api.ipify.org/?format=json",
        };

        const request = rp(options);
        const response = await Promise.race([request, delay(request, 500000)]);

        console.log(response)

    } catch (e) {
        console.log(e) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js

1
推荐指数
1
解决办法
1328
查看次数

如何在不使用 new 和 delete 的情况下实例化抽象类?

考虑以下代码,

class Interface
{
public:
    Interface(){}
    virtual ~Interface(){}
    virtual void method1() = 0; 
                                  
    virtual void method2() = 0;
};

class Concrete : public Interface
{
private:
    int myMember;

public:
    Concrete(){}
    ~Concrete(){}
    void method1();
    void method2();
};

void Concrete::method1()
{
    // Your implementation
}

void Concrete::method2()
{
    // Your implementation
}

int main(void)
{
    Interface *f = new Concrete();

    f->method1();
    f->method2();

    delete f;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

笔者使用的Interface *f = new Concrete();实例在主函数一个抽象类,后来他用delete f;,但这个问题newdelete …

c++

1
推荐指数
1
解决办法
85
查看次数

复制赋值运算符隐式删除,因为字段具有已删除的复制赋值运算符

一旦定义析构函数,我就会收到此错误,但如果没有编译成功,但我非常想定义析构函数来调试一些段错误。

class Socket {
    private:
        seastar::output_stream<char> socket;

    public:
        std::string peer;
    public:
        Socket() = default;

        template <typename... Args>
        explicit Socket(seastar::output_stream<char> &&s, std::string p) : socket(std::move(s)), peer(p) {}

        ~Socket() {
            std::cout << "Socket has gone out of scope" << "\n";
        }

        seastar::future<> send(std::string message) {
            co_await socket.write(message);
            co_await socket.flush();
        }

        seastar::future<> close() {
            co_await socket.close();
        }
};
Run Code Online (Sandbox Code Playgroud)

编译失败,

error: object of type 'Socket' cannot be assigned because its copy assignment operator is implicitly deleted
        connection->second.socketObj = std::move(socketObj);
                                  ^
./socketwrapper.h:44:46: note: copy assignment …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
4533
查看次数