From: Cliff Woolley Date: Thu, 23 Aug 2001 02:23:43 +0000 (+0000) Subject: Another step in improving legibility by factoring out some redundant code X-Git-Tag: 2.0.25~160 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5bfeab91b58524385abdb812a6bf101959d9566;p=apache Another step in improving legibility by factoring out some redundant code (how many times can you test the same condition in one function? :-) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90535 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c index f5a22ee37f..a3f80b87d7 100644 --- a/modules/ssl/ssl_engine_io.c +++ b/modules/ssl/ssl_engine_io.c @@ -74,38 +74,37 @@ static const char ssl_io_filter[] = "SSL/TLS Filter"; static int ssl_io_hook_read(SSL *ssl, unsigned char *buf, int len) { - conn_rec *c; int rc; - if (ssl != NULL) { - rc = SSL_read(ssl, buf, len); - /* - * Simulate an EINTR in case OpenSSL wants to read more. - * (This is usually the case when the client forces an SSL - * renegotation which is handled implicitly by OpenSSL.) - */ - if (rc < 0 && SSL_get_error(ssl, rc) == SSL_ERROR_WANT_READ) + if (ssl == NULL) { + return -1; + } + + rc = SSL_read(ssl, buf, len); + + if (rc < 0) { + int ssl_err = SSL_get_error(ssl, rc); + + if (ssl_err == SSL_ERROR_WANT_READ) { + /* + * Simulate an EINTR in case OpenSSL wants to read more. + * (This is usually the case when the client forces an SSL + * renegotation which is handled implicitly by OpenSSL.) + */ errno = EINTR; - /* - * Log SSL errors - */ - if (rc < 0 && SSL_get_error(ssl, rc) == SSL_ERROR_SSL) { - c = (conn_rec *)SSL_get_app_data(ssl); + } + else if (ssl_err == SSL_ERROR_SSL) { + /* + * Log SSL errors + */ + conn_rec *c = (conn_rec *)SSL_get_app_data(ssl); ssl_log(c->base_server, SSL_LOG_ERROR|SSL_ADD_SSLERR, "SSL error on reading data"); } /* - * read(2) returns only the generic error number -1 + * XXX - Just trying to reflect the behaviour in + * openssl_state_machine.c [mod_tls]. TBD */ - if (rc < 0) { - /* - * XXX - Just trying to reflect the behaviour in - * openssl_state_machine.c [mod_tls]. TBD - */ - rc = -1; - } - } - else { rc = -1; } return rc; @@ -113,37 +112,36 @@ static int ssl_io_hook_read(SSL *ssl, unsigned char *buf, int len) static int ssl_io_hook_write(SSL *ssl, unsigned char *buf, int len) { - conn_rec *c; int rc; - if (ssl != NULL) { - rc = SSL_write(ssl, buf, len); - /* - * Simulate an EINTR in case OpenSSL wants to write more. - */ - if (rc < 0 && SSL_get_error(ssl, rc) == SSL_ERROR_WANT_WRITE) + if (ssl == NULL) { + return -1; + } + + rc = SSL_write(ssl, buf, len); + + if (rc < 0) { + int ssl_err = SSL_get_error(ssl, rc); + + if (ssl_err == SSL_ERROR_WANT_WRITE) { + /* + * Simulate an EINTR in case OpenSSL wants to write more. + */ errno = EINTR; - /* - * Log SSL errors - */ - if (rc < 0 && SSL_get_error(ssl, rc) == SSL_ERROR_SSL) { - c = (conn_rec *)SSL_get_app_data(ssl); + } + else if (ssl_err == SSL_ERROR_SSL) { + /* + * Log SSL errors + */ + conn_rec *c = (conn_rec *)SSL_get_app_data(ssl); ssl_log(c->base_server, SSL_LOG_ERROR|SSL_ADD_SSLERR, "SSL error on writing data"); } /* - * write(2) returns only the generic error number -1 + * XXX - Just trying to reflect the behaviour in + * openssl_state_machine.c [mod_tls]. TBD */ - if (rc < 0) { - /* - * XXX - Just trying to reflect the behaviour in - * openssl_state_machine.c [mod_tls]. TBD - */ - rc = 0; - } - } - else { - rc = -1; + rc = 0; } return rc; }