comparison 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
comparison
equal deleted inserted replaced
361:446782c909b3 362:7650aea1816f
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <ngx_aio.h> 5 #include <ngx_aio.h>
6 6
7 7
8 ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in) 8 ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
9 off_t limit)
9 { 10 {
10 int n; 11 int n;
11 u_char *buf, *prev; 12 u_char *buf, *prev;
12 off_t sent; 13 off_t send, sent;
13 size_t size; 14 size_t len;
15 ssize_t size;
14 ngx_err_t err; 16 ngx_err_t err;
15 ngx_chain_t *cl; 17 ngx_chain_t *cl;
16 18
19 send = 0;
17 sent = 0; 20 sent = 0;
18 cl = in; 21 cl = in;
19 22
20 while (cl) { 23 while (cl) {
21 24
22 if (cl->buf->last - cl->buf->pos == 0) { 25 if (cl->buf->pos == cl->buf->last) {
23 cl = cl->next; 26 cl = cl->next;
24 continue; 27 continue;
25 } 28 }
26 29
27 /* we can post the single aio operation only */ 30 /* we can post the single aio operation only */
30 return cl; 33 return cl;
31 } 34 }
32 35
33 buf = cl->buf->pos; 36 buf = cl->buf->pos;
34 prev = buf; 37 prev = buf;
35 size = 0; 38 len = 0;
36 39
37 /* coalesce the neighbouring bufs */ 40 /* coalesce the neighbouring bufs */
38 41
39 while (cl && prev == cl->buf->pos) { 42 while (cl && prev == cl->buf->pos && send < limit) {
40 size += cl->buf->last - cl->buf->pos; 43 if (ngx_buf_special(cl->buf)) {
41 prev = cl->buf->last; 44 continue;
45 }
46
47 size = cl->buf->last - cl->buf->pos;
48
49 if (send + size > limit) {
50 size = limit - send;
51 }
52
53 len += size;
54 prev = cl->buf->pos + size;
55 send += size;
42 cl = cl->next; 56 cl = cl->next;
43 } 57 }
44 58
45 n = ngx_aio_write(c, buf, size); 59 n = ngx_aio_write(c, buf, len);
46 60
47 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n); 61 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n);
48 62
49 if (n == NGX_ERROR) { 63 if (n == NGX_ERROR) {
50 return NGX_CHAIN_ERROR; 64 return NGX_CHAIN_ERROR;