【发布时间】:2015-10-15 06:37:50
【问题描述】:
在我的 C++ 应用程序中,我使用 OpenSSL 通过非阻塞 BIO 连接到服务器。我正在为 mac OS X 和 iOS 开发。
第一次调用SSL_shutdown() 返回0。这意味着我必须再次调用SSL_shutdown():
可能出现以下返回值:
0 关机尚未完成。如果要执行双向关闭,则再次调用 SSL_shutdown()。 SSL_get_error 的输出可能会产生误导,因为即使没有发生错误,也可能会标记错误的 SSL_ERROR_SYSCALL。
https://www.openssl.org/docs/ssl/SSL_shutdown.html
到目前为止,上帝。第二次调用SSL_shutdown() 时出现问题。这将返回 -1,这意味着发生了错误(见上文)。现在,如果我检查 SSL_get_error() 我会收到错误 SSL_ERROR_SYSCALL 这反过来应该意味着发生了系统错误。但现在抓住了。如果我检查 errno 它返回 0 -> 未知错误。到目前为止,我所读到的关于这个问题的内容是,这可能意味着服务器只是“挂断了”,但老实说,这并不能让我满意。
这是我的关机实现:
int result = 0;
int shutdownResult;
while ((shutdownResult = SSL_shutdown(sslHandle)) != 1) { //close connection 1 means everything is shut down ok
if (shutdownResult == 0) { //we are supposed to call shutdown again
continue;
} else if (SSL_get_error(sslHandle, shutdownResult) == SSL_ERROR_WANT_READ) {
[...] //omitted want read code, in this case the application never reaches this point
} else if (SSL_get_error(sslHandle, shutdownResult) == SSL_ERROR_WANT_WRITE) {
[...] //omitted want write code, in this case the application never reaches this point
} else {
logError("Error in ssl shutdown, ssl error: " + std::to_string(SSL_get_error(sslHandle, shutdownResult)) + ", system error: " + std::string(strerror(errno))); //something went wrong
break;
}
}
运行应用程序日志时:
ERROR:: ssl 关闭错误,ssl 错误:5,系统错误:未定义错误:0
那么这里只是服务器关闭连接还是有更严重的问题?我只是错过了一些非常明显的东西吗?
【问题讨论】:
-
你有自定义 BIO 吗?
-
不,我不创建自定义 BIO
标签: c++ ssl openssl nonblocking system-error