C 无法使用OpenSSL BIO接口建立连接

C 无法使用OpenSSL BIO接口建立连接,c,networking,openssl,connection,C,Networking,Openssl,Connection,我正在VS2010中调试。BIO_do_connect()在以下代码中失败。我做错了什么 (使用前正确设置pBio) 似乎如果我增加睡眠间隔(例如,增加到500),BIO_do_connect可以正常工作,但我想知道为什么间隔值较短会失败。自从发布我的原始问题以来,我已切换到使用select(),因此问题不再有效 而不是做 uTimeTaken += kuSleepIntervalInMs; 我现在正在做: int nRet; int fdSocket; fd_set connectionfd

我正在VS2010中调试。BIO_do_connect()在以下代码中失败。我做错了什么

(使用前正确设置pBio)


似乎如果我增加睡眠间隔(例如,增加到500),BIO_do_connect可以正常工作,但我想知道为什么间隔值较短会失败。

自从发布我的原始问题以来,我已切换到使用select(),因此问题不再有效

而不是做

uTimeTaken += kuSleepIntervalInMs;
我现在正在做:

int nRet;
int fdSocket;
fd_set connectionfds;
struct timeval timeout;

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.

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.
}
intnret;
int-fdSocket;
fd_集连接FDS;
结构timeval超时;
生物组(pBio,1);
nRet=生物连接(pBio);
如果((nRet
int nRet;
int fdSocket;
fd_set connectionfds;
struct timeval timeout;

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.

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.
}