diff src/event/ngx_event_openssl.c @ 330:5e3b425174f6 NGINX_0_6_9

nginx 0.6.9 *) Bugfix: a worker process may got caught in an endless loop, if the HTTPS protocol was used; bug appeared in 0.6.7. *) Bugfix: if server listened on two addresses or ports and trailing wildcard was used, then nginx did not run. *) Bugfix: the "ip_hash" directive might incorrectly mark servers as down. *) Bugfix: nginx could not be built on amd64; bug appeared in 0.6.8.
author Igor Sysoev <http://sysoev.ru>
date Tue, 28 Aug 2007 00:00:00 +0400
parents f7cd062ee035
children 3a91bfeffaba
line wrap: on
line diff
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -593,10 +593,13 @@ ngx_ssl_recv(ngx_connection_t *c, u_char
     int  n, bytes;
 
     if (c->ssl->last == NGX_ERROR) {
+        c->read->error = 1;
         return NGX_ERROR;
     }
 
     if (c->ssl->last == NGX_DONE) {
+        c->read->ready = 0;
+        c->read->eof = 1;
         return 0;
     }
 
@@ -619,26 +622,38 @@ ngx_ssl_recv(ngx_connection_t *c, u_char
 
         c->ssl->last = ngx_ssl_handle_recv(c, n);
 
-        if (c->ssl->last != NGX_OK) {
-
-            if (bytes) {
+        if (c->ssl->last == NGX_OK) {
+
+            size -= n;
+
+            if (size == 0) {
                 return bytes;
             }
 
-            if (c->ssl->last == NGX_DONE) {
-                return 0;
-            }
-
+            buf += n;
+
+            continue;
+        }
+
+        if (bytes) {
+            return bytes;
+        }
+
+        switch (c->ssl->last) {
+
+        case NGX_DONE:
+            c->read->ready = 0;
+            c->read->eof = 1;
+            return 0;
+
+        case NGX_ERROR:
+            c->read->error = 1;
+
+            /* fall thruogh */
+
+        case NGX_AGAIN:
             return c->ssl->last;
         }
-
-        size -= n;
-
-        if (size == 0) {
-            return bytes;
-        }
-
-        buf += n;
     }
 }
 
@@ -703,7 +718,6 @@ ngx_ssl_handle_recv(ngx_connection_t *c,
 
     c->ssl->no_wait_shutdown = 1;
     c->ssl->no_send_shutdown = 1;
-    c->read->eof = 1;
 
     if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) {
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
@@ -711,7 +725,6 @@ ngx_ssl_handle_recv(ngx_connection_t *c,
         return NGX_DONE;
     }
 
-    c->read->error = 1;
     ngx_ssl_connection_error(c, sslerr, err, "SSL_read() failed");
 
     return NGX_ERROR;