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-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d113cb7e0dd4c280aeab70706182325f59b1f6b;p=thirdparty%2Fapache%2Fhttpd.git 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/modules/ssl@90535 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/ssl_engine_io.c b/ssl_engine_io.c index f5a22ee37fa..a3f80b87d77 100644 --- a/ssl_engine_io.c +++ b/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; }