gpt4 book ai didi

c++ - boost SSL 连接的同时连接问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:01:41 37 4
gpt4 key购买 nike

下面的伪代码解释了我面临的情况

服务器端

while (<some condition>)
{
// wait for SSL connection
acceptor.async_accept();

// wait until connection
io_service.run();

// perform handshake
ssl_socket.handhake();

// handshake successfully complete, start command manager thread
pthread_create();

io_service.reset();
// Go for the new connection waiting
}

这里的问题是我可以连接两个客户端,但不能同时连接。1 个连接到达后,握手和证书验证需要 40-50 毫秒,因此中间的任何连接请求都会失败。

更新:

有什么办法可以在握手过程中停止监听客户端问候吗?我必须为每个循环创建新的 io_service 实例,因为我可能想使用 io_service.stop() 调用取消特定线程。 boost 是否有任何其他选择?

最佳答案

同步 ssl_socket.handshake() 将阻止接受额外的连接。如果您需要异步行为,请使用 ssl_socket.async_handshake()

另外值得注意的是:您不需要为每个线程建立一个连接,因为该设计不会扩展到超出普通示例的范围。

关于c++ - boost SSL 连接的同时连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20996033/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com