nginx-0.1.12-RELEASE import

    *) Feature: the %request_length log parameter.

    *) Bugfix: when using the /dev/poll, select and poll on the platforms,
       where these methods may do the false reports, there may be the long
       delay when the request was passed via the keep-alive connection. It
       may be at least on Solaris when using the /dev/poll.

    *) Bugfix: the send_lowat directive is ignored on Linux because Linux
       does not support the SO_SNDLOWAT option.
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index fe3d516..b2c3516 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -795,6 +795,8 @@
             ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                            "http header done");
 
+            r->request_length += r->header_in->pos - r->header_in->start;
+
             r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE;
 
             rc = ngx_http_process_request_header(r);
@@ -922,6 +924,8 @@
 
         /* the client fills up the buffer with "\r\n" */
 
+        r->request_length += r->header_in->end - r->header_in->start;
+
         r->header_in->pos = r->header_in->start;
         r->header_in->last = r->header_in->start;
 
@@ -981,6 +985,8 @@
          * to relocate the parser header pointers
          */
 
+        r->request_length += r->header_in->end - r->header_in->start;
+
         r->header_in = b;
 
         return NGX_OK;
@@ -989,6 +995,8 @@
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http large header copy: %d", r->header_in->pos - old);
 
+    r->request_length += old - r->header_in->start;
+
     new = b->start;
 
     ngx_memcpy(new, old, r->header_in->pos - old);
@@ -1810,6 +1818,10 @@
     c->log_error = NGX_ERROR_INFO;
 
     if (n == NGX_AGAIN) {
+        if (ngx_handle_level_read_event(rev) == NGX_ERROR) {
+            ngx_http_close_connection(c);
+        }
+
         return;
     }
 
@@ -1932,6 +1944,11 @@
 
     } while (rev->ready);
 
+    if (ngx_handle_level_read_event(rev) == NGX_ERROR) {
+        ngx_http_close_connection(c);
+        return;
+    }
+
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
     timer *= 1000;