Hi All,
I am opening a SSL connection from a client. The underlying socket and
BIO are non-blocking. I am observing that SSL_connect is executing
three times before it completes. While the first and the last call
return almost immediately (less than 1 ms), the intermediate call
takes 11 ms. Is this expected behavior? Why does SSL wait so long to
return? Any help please?
The code:
/* socket opened, made non blocking and a non-blocking
tcp_connect is completed. */
ssl = SSL_new(ctx);
sbio = BIO_new_socket(sock, BIO_NOCLOSE);
BIO_set_nbio(sbio, 1);
SSL_set_bio(ssl, sbio, sbio);
t_epfd = epoll_create(EPOLL_INIT_SIZE);
epoll_control(t_epfd, EPOLL_CTL_ADD, sock, EPOLLOUT);
printf("====== Will start connecting\n");
while (TRUE)
{
gettimeofday(&test_tv, NULL);
r_code = SSL_connect(ssl); dbg_connect_count++;
printf("%d: SSL connect returned in %f\n", dbg_connect_count,
tvdiff_msec(&test_tv, NULL));
if (r_code == 1)
break;
switch(SSL_get_error(ssl, r_code))
{
case SSL_ERROR_WANT_WRITE:
printf("SSL: want write\n");
epoll_control(t_epfd, EPOLL_CTL_MOD, sock,
EPOLLOUT);
break;
case SSL_ERROR_WANT_READ: // In progress, go back
and wait
printf("SSL: want read\n");
epoll_control(t_epfd, EPOLL_CTL_MOD, sock,
EPOLLIN);
break;
default:
printf("Error\n");
exit(0);
break;
}
epoll_wait(t_epfd, events, MAXEVENTS, -1);
}
printf("====== SSL connected\n");
And the output:
====== Will start connecting
1: SSL connect returned in 0.126000
SSL: want read
2: SSL connect returned in 11.259000
SSL: want read
3: SSL connect returned in 0.063000
====== SSL connected
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]