comparison src/os/unix/ngx_aio_write_chain.c @ 164:84036764e215

nginx-0.0.1-2003-10-29-11:30:44 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 29 Oct 2003 08:30:44 +0000
parents ef8c87afcfc5
children 389d7ee9fa60
comparison
equal deleted inserted replaced
163:fb61ba77beba 164:84036764e215
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 { 9 {
10 int rc; 10 int n;
11 char *buf, *prev; 11 char *buf, *prev;
12 off_t sent; 12 off_t sent;
13 size_t size; 13 size_t size;
14 ngx_err_t err; 14 ngx_err_t err;
15 ngx_chain_t *ce; 15 ngx_chain_t *cl;
16 16
17 sent = 0; 17 sent = 0;
18 ce = in; 18 cl = in;
19 19
20 while (ce) { 20 while (cl) {
21
22 if (cl->hunk->last - cl->hunk->pos == 0) {
23 cl = cl->next;
24 continue;
25 }
21 26
22 /* we can post the single aio operation only */ 27 /* we can post the single aio operation only */
23 28
24 if (c->write->active) { 29 if (c->write->active) {
25 return ce; 30 return cl;
26 } 31 }
27 32
28 buf = prev = ce->hunk->pos; 33 buf = cl->hunk->pos;
34 prev = buf;
29 size = 0; 35 size = 0;
30 36
31 /* coalesce the neighbouring chain entries */ 37 /* coalesce the neighbouring hunks */
32 38
33 while (ce && prev == ce->hunk->pos) { 39 while (cl && prev == cl->hunk->pos) {
34 size += ce->hunk->last - ce->hunk->pos; 40 size += cl->hunk->last - cl->hunk->pos;
35 prev = ce->hunk->last; 41 prev = cl->hunk->last;
36 ce = ce->next; 42 cl = cl->next;
37 } 43 }
38 44
39 rc = ngx_aio_write(c, buf, size); 45 n = ngx_aio_write(c, buf, size);
40 46
41 #if (NGX_DEBUG_WRITE_CHAIN) 47 #if (NGX_DEBUG_WRITE_CHAIN)
42 ngx_log_debug(c->log, "aio_write rc: %d" _ rc); 48 ngx_log_debug(c->log, "aio_write: %d" _ n);
43 #endif 49 #endif
44 50
45 if (rc == NGX_ERROR) { 51 if (n == NGX_ERROR) {
46 return NGX_CHAIN_ERROR; 52 return NGX_CHAIN_ERROR;
47 } 53 }
48 54
49 if (rc > 0) { 55 if (n > 0) {
50 sent += rc; 56 sent += n;
51 c->sent += rc; 57 c->sent += n;
52 } 58 }
53 59
54 #if (NGX_DEBUG_WRITE_CHAIN) 60 #if (NGX_DEBUG_WRITE_CHAIN)
55 ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent); 61 ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent);
56 #endif 62 #endif
57 63
58 for (ce = in; ce; ce = ce->next) { 64 for (cl = in; cl; cl = cl->next) {
59 65
60 if (sent >= ce->hunk->last - ce->hunk->pos) { 66 if (sent >= cl->hunk->last - cl->hunk->pos) {
61 sent -= ce->hunk->last - ce->hunk->pos; 67 sent -= cl->hunk->last - cl->hunk->pos;
62 ce->hunk->pos = ce->hunk->last; 68 cl->hunk->pos = cl->hunk->last;
63 69
64 continue; 70 continue;
65 } 71 }
66 72
67 ce->hunk->pos += sent; 73 cl->hunk->pos += sent;
68 74
69 break; 75 break;
70 } 76 }
71 } 77 }
72 78
73 return ce; 79 return cl;
74 } 80 }