diff src/os/unix/ngx_aio_write_chain.c @ 362:7650aea1816f

nginx-0.0.7-2004-06-21-19:59:32 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 21 Jun 2004 15:59:32 +0000
parents 6bdf858bff8c
children da8c5707af39
line wrap: on
line diff
--- a/src/os/unix/ngx_aio_write_chain.c
+++ b/src/os/unix/ngx_aio_write_chain.c
@@ -5,21 +5,24 @@
 #include <ngx_aio.h>
 
 
-ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in)
+ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
+                                 off_t limit)
 {
     int           n;
     u_char       *buf, *prev;
-    off_t         sent;
-    size_t        size;
+    off_t         send, sent;
+    size_t        len;
+    ssize_t       size;
     ngx_err_t     err;
     ngx_chain_t  *cl;
 
+    send = 0;
     sent = 0;
     cl = in;
 
     while (cl) {
 
-        if (cl->buf->last - cl->buf->pos == 0) {
+        if (cl->buf->pos == cl->buf->last) {
             cl = cl->next;
             continue;
         }
@@ -32,17 +35,28 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con
 
         buf = cl->buf->pos;
         prev = buf;
-        size = 0;
+        len = 0;
 
         /* coalesce the neighbouring bufs */
 
-        while (cl && prev == cl->buf->pos) {
-            size += cl->buf->last - cl->buf->pos;
-            prev = cl->buf->last;
+        while (cl && prev == cl->buf->pos && send < limit) {
+            if (ngx_buf_special(cl->buf)) {
+                continue;
+            }
+
+            size = cl->buf->last - cl->buf->pos;
+
+            if (send + size > limit) {
+                size = limit - send;
+            }
+
+            len += size;
+            prev = cl->buf->pos + size;
+            send += size;
             cl = cl->next;
         }
 
-        n = ngx_aio_write(c, buf, size);
+        n = ngx_aio_write(c, buf, len);
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n);