From f2dabd56b755425e42cab2cd6599772e2253bbbb Mon Sep 17 00:00:00 2001 From: cameronrich Date: Fri, 14 Jan 2011 13:57:34 +0000 Subject: [PATCH] Allow non-blocked ssl_client_new() operation. git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@194 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- ssl/ssl.h | 1 + ssl/tls1_clnt.c | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ssl/ssl.h b/ssl/ssl.h index 009944046..6778837f9 100644 --- a/ssl/ssl.h +++ b/ssl/ssl.h @@ -82,6 +82,7 @@ extern "C" { #define SSL_DISPLAY_BYTES 0x00100000 #define SSL_DISPLAY_CERTS 0x00200000 #define SSL_DISPLAY_RSA 0x00400000 +#define SSL_CLIENT_NON_BLOCKING 0x00800000 /* errors that can be generated */ #define SSL_OK 0 diff --git a/ssl/tls1_clnt.c b/ssl/tls1_clnt.c index cb1be7724..510126ab1 100644 --- a/ssl/tls1_clnt.c +++ b/ssl/tls1_clnt.c @@ -151,23 +151,26 @@ int do_client_connect(SSL *ssl) ssl->hs_status = SSL_NOT_OK; /* not connected */ /* sit in a loop until it all looks good */ - while (ssl->hs_status != SSL_OK) + if (!IS_SET_SSL_FLAG(SSL_CLIENT_NON_BLOCKING)) { - ret = basic_read(ssl, NULL); - - if (ret < SSL_OK) - { - if (ret != SSL_ERROR_CONN_LOST) - { - /* let the server know we are dying and why */ - if (send_alert(ssl, ret)) + while (ssl->hs_status != SSL_OK) + { + ret = basic_read(ssl, NULL); + + if (ret < SSL_OK) + { + if (ret != SSL_ERROR_CONN_LOST) { - /* something nasty happened, so get rid of it */ - kill_ssl_session(ssl->ssl_ctx->ssl_sessions, ssl); + /* let the server know we are dying and why */ + if (send_alert(ssl, ret)) + { + /* something nasty happened, so get rid of it */ + kill_ssl_session(ssl->ssl_ctx->ssl_sessions, ssl); + } } - } - break; + break; + } } }