无法建立使用OpenSSL BIO接口连接 [英] Unable to establish connection using OpenSSL BIO interface
问题描述
我调试在VS2010。 BIO_do_connect()失败在以下code。我在做什么错了?
I'm debugging in VS2010. BIO_do_connect() fails in the following code. What am I doing wrong?
(PBIO正确设置使用前)
(pBio is properly set up before use)
static const uint32_t kuSleepIntervalInMs = 50;
...
uint32_t uTimeTaken = 0;
...
BIO_set_nbio(pBio, 1);
for (;;)
{
if (uTimeTaken > 10000)
return ERR_CONNECTION_TIMED_OUT;
if (BIO_do_connect(pBio) > 0)
break;
if (BIO_should_retry(pBio))
{
Sleep(kuSleepIntervalInMs);
uTimeTaken += kuSleepIntervalInMs;
continue;
}
BIO_free_all(pBio);
return ERR_FAILED_TO_ESTABLISH_CONNECTION;
}
看来,如果我增加睡眠间隔(例如500),BIO_do_connect工作正常,但我想知道为什么失败,较短的时间间隔值。
It appears that if I increase the sleep interval (for example to 500), BIO_do_connect works fine but I'd like to know why it fails with shorter interval values.
推荐答案
由于张贴我原来的问题,我已经切换到使用select(),所以这个问题是不再有效。
Since posting my original question, I've switched to use select() so the problem is no longer valid.
而不是做的
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.
}
见我的其他<一个href=\"http://stackoverflow.com/questions/15852840/c-how-to-set-connection-timeout-and-operation-timeout-in-openssl\">post.
这篇关于无法建立使用OpenSSL BIO接口连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!