如何压制"ERROR message: short read (SSL routines, SSL routines), value: 335544539"

How to suppress "ERROR message: short read (SSL routines, SSL routines), value: 335544539"

参考: websocket_client_sync_ssl.cpp

// Read a message into our buffer
ws.read(buffer);

// Close the WebSocket connection
ws.close(websocket::close_code::normal);
    

根据我的测试,ws.close 会发出以下警告:

ERROR message: short read (SSL routines, SSL routines), value: 335544539

基于此post short read,在会话结束时可以安全地忽略此错误。我尝试了以下方法来抑制警告:

try
{
  boost::system::error_code close_ec;
  ws.close(websocket::close_code::normal, close_ec);
  if (close_ec)
  {
    std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
  }
}
catch(...)
{

}
    

但是,ws.close 仍然打印出警告消息。

问题> 有什么方法可以抑制这条消息吗?

However, the ws.close still prints out the warning message.

你确定吗?看起来这只是来自以下行:

std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;

因此,您将检查 close_ec 的值并有条件地处理它:

另外请注意,某些类型的“短读”可能会构成安全错误。一些样本有 very insightful comments about this:

// `net::ssl::error::stream_truncated`, also known as an SSL "short read",
// indicates the peer closed the connection without performing the
// required closing handshake (for example, Google does this to
// improve performance). Generally this can be a security issue,
// but if your communication protocol is self-terminated (as
// it is with both HTTP and WebSocket) then you may simply
// ignore the lack of close_notify:
//
// https://github.com/boostorg/beast/issues/38
//
// https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown
//
// When a short read would cut off the end of an HTTP message,
// Beast returns the error beast::http::error::partial_message.
// Therefore, if we see a short read here, it has occurred
// after the message has been completed, so it is safe to ignore it.

if(ec == net::ssl::error::stream_truncated)
    ec = {};
else if(ec)
    return;