为什么 BIO_get_fd() 在下面这段代码中总是无法获得有效的 FD?
SSL *pSsl = NULL;
int nRet;
int fdSocket;
fd_set connectionfds;
struct timeval timeout;
BIO_get_ssl(pBio, &pSsl);
if (!pSsl)
// failed to get SSL pointer of BIO.
SSL_set_mode(pSsl, SSL_MODE_AUTO_RETRY);
BIO_set_conn_hostname(pBio, "HostName");
BIO_set_conn_port(pBio, "PortNumber");
BIO_set_nbio(pBio, 1);
nRet = BIO_do_connect(pBio);
if ((nRet <= 0) && !BIO_should_retry(pBio))
// failed to establish connection.
if (BIO_get_fd(pBio, &fdSocket) <= 0)
// failed to get fd but why?
if (nRet <= 0)
{
FD_ZERO(&connectionfds);
FD_SET(fdSocket, &connectionfds);
timeout.tv_usec = 0;
timeout.tv_sec = 10;
nRet = select(fdSocket + 1, NULL, &connectionfds, NULL, &timeout);
if (nRet == 0)
// timeout has occurred.
}
- 我的 BIO 对象是通过调用 BIO *BIO_new_ssl_connect(SSL_CTX *ctx) 预先正确创建的
- 我的 OpenSSL 版本是 v1.0.1e
- 我在 Ubuntu for ARM 上进行交叉编译