关闭boost asio ssl套接字时需要调用ssl :: stream :: shutdown吗? [英] need to call ssl::stream::shutdown when closing boost asio ssl socket?
问题描述
我的代码如下:
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
时,都会出现错误.这种未知错误具有很大的错误值.
Each time I call m_remote_socket.shutdown
, it will get an error. Such kind of unknown error with a really big error value.
但是直接调用m_remote_socket.lowest_layer().shutdown()
而不调用m_remote_socket.shutdown
是可以的.
But it is ok to call m_remote_socket.lowest_layer().shutdown()
directly without calling m_remote_socket.shutdown
.
有人可以告诉我如何关闭ssl流媒体套接字吗?
Could anybody tell me how to close a ssl streaming socket?
推荐答案
在ssl::stream
及其lowest_layer()
上都进行shutdown()
调用是最干净的.第一个结束SSL连接,第二个
It is cleanest to make shutdown()
calls on both the ssl::stream
and its lowest_layer()
. The first ends the SSL connection and the second ends the TCP connection. If you're getting an error on the SSL shutdown, it may be that the other side is not being as graceful in ending the connection.
这篇关于关闭boost asio ssl套接字时需要调用ssl :: stream :: shutdown吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!