From ff75a25749c7fceaff7503af6f09d4299a052996 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Mon, 25 Jan 2016 15:28:57 +0000 Subject: Refactor the async wait fd logic Implementation experience has shown that the original plan for async wait fds was too simplistic. Originally the async logic created a pipe internally and user/engine code could then get access to it via API calls. It is more flexible if the engine is able to create its own fd and provide it to the async code. Another issue is that there can be a lot of churn in the fd value within the context of (say) a single SSL connection leading to continually adding and removing fds from (say) epoll. It is better if we can provide some stability of the fd value across a whole SSL connection. This is problematic because an engine has no concept of an SSL connection. This commit refactors things to introduce an ASYNC_WAIT_CTX which acts as a proxy for an SSL connection down at the engine layer. Reviewed-by: Richard Levitte --- ssl/ssl_lib.c | 29 ++++++++++++++++++++++++----- ssl/ssl_locl.h | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'ssl') diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 0cbb024a55..359b58b996 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -1055,6 +1055,8 @@ void SSL_free(SSL *s) SSL_CTX_free(s->ctx); + ASYNC_WAIT_CTX_free(s->waitctx); + #if !defined(OPENSSL_NO_NEXTPROTONEG) OPENSSL_free(s->next_proto_negotiated); #endif @@ -1399,12 +1401,24 @@ int SSL_waiting_for_async(SSL *s) return 0; } -int SSL_get_async_wait_fd(SSL *s) +int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds) { - if (!s->job) - return -1; + ASYNC_WAIT_CTX *ctx = s->waitctx; + + if (ctx == NULL) + return 0; + return ASYNC_WAIT_CTX_get_all_fds(ctx, fds, numfds); +} - return ASYNC_get_wait_fd(s->job); +int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd, size_t *numaddfds, + OSSL_ASYNC_FD *delfd, size_t *numdelfds) +{ + ASYNC_WAIT_CTX *ctx = s->waitctx; + + if (ctx == NULL) + return 0; + return ASYNC_WAIT_CTX_get_changed_fds(ctx, addfd, numaddfds, delfd, + numdelfds); } int SSL_accept(SSL *s) @@ -1435,7 +1449,12 @@ long SSL_get_default_timeout(const SSL *s) static int ssl_start_async_job(SSL *s, struct ssl_async_args *args, int (*func)(void *)) { int ret; - switch(ASYNC_start_job(&s->job, &ret, func, args, + if (s->waitctx == NULL) { + s->waitctx = ASYNC_WAIT_CTX_new(); + if (s->waitctx == NULL) + return -1; + } + switch(ASYNC_start_job(&s->job, s->waitctx, &ret, func, args, sizeof(struct ssl_async_args))) { case ASYNC_ERR: s->rwstate = SSL_NOTHING; diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index f4d1ddcbc4..4fc079baed 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -1175,6 +1175,7 @@ struct ssl_st { /* Async Job info */ ASYNC_JOB *job; + ASYNC_WAIT_CTX *waitctx; }; -- cgit v1.2.3