gpt4 book ai didi

c++ - 关闭 boost asio ssl 套接字时需要调用 ssl::stream::shutdown 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:34 24 4
gpt4 key购买 nike

我的代码如下:

declaration: boost::asio::ssl::stream<boost::asio::ip::tcp::socket> m_remote_socket;

m_remote_socket.shutdown(ec);
if (ec)
{
cdbug<<"id: "<<m_id<<", error when ssl shutdown: " <<boost::system::system_category().message(ec.value()).c_str();
}
m_remote_socket.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
if (ec)
{
cdbug<<"id: "<<m_id<<", error when tcp shutdown: "<<boost::system::system_category().message(ec.value()).c_str();
}

每次调用 m_remote_socket.shutdown 时,它都会出错。这种错误值非常大的未知错误。

但是不调用m_remote_socket.shutdown直接调用m_remote_socket.lowest_layer().shutdown()也是可以的。

谁能告诉我如何关闭 ssl 流套接字?

最佳答案

ssl::stream 及其 lowest_layer() 进行 shutdown() 调用是最干净的。第一个ends the SSL connection第二个ends the TCP connection .如果您在 SSL 关闭时遇到错误,可能是另一端在结束连接时没有那么优雅。

关于c++ - 关闭 boost asio ssl 套接字时需要调用 ssl::stream::shutdown 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15312219/

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