Rij wrote: > I am using a non-blocking socket to connect to a server. I have the > following code which works fine. The issue is that the while loop > executes almost 3000 times! Is this expected? When I am waiting for > select/epoll to return, I was expecting it to return only when the > connection completes, much like blocking connect(). Is there a better > way of writing the code? > > Thanks, Rij > > ssl = SSL_new(ctx); > sbio = BIO_new_socket(sock, BIO_NOCLOSE); > SSL_set_bio(ssl, sbio, sbio); > connected = 0; > while (1) > { > r_code = SSL_connect(ssl); > if (r_code == 1) > break; > > switch(SSL_get_error(ssl, r_code)) > { > case SSL_ERROR_WANT_WRITE: > case SSL_ERROR_WANT_READ: > /* Wait for epoll/select to return > */ > break; > } > }
It's hard to tell without seeing the code that you've replaced with a comment, but one thing is obvious -- your code folds both SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE into the same code path. So how does it know which direction to wait for? If you get SSL_ERROR_WANT_READ, you need to epoll/select for readability. If you get SSL_ERROR_WANT_WRITE, you need to epoll/select for readability. DS ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org