Mercurial > hg > nginx
comparison src/os/unix/ngx_aio_write_chain.c @ 144:ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 12 Oct 2003 16:49:16 +0000 |
parents | b48066122884 |
children | 84036764e215 |
comparison
equal
deleted
inserted
replaced
143:5526213be452 | 144:ef8c87afcfc5 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | |
4 #include <ngx_aio.h> | 5 #include <ngx_aio.h> |
5 | 6 |
6 | 7 |
7 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) |
8 { | 9 { |
15 | 16 |
16 sent = 0; | 17 sent = 0; |
17 ce = in; | 18 ce = in; |
18 | 19 |
19 while (ce) { | 20 while (ce) { |
21 | |
22 /* we can post the single aio operation only */ | |
23 | |
24 if (c->write->active) { | |
25 return ce; | |
26 } | |
27 | |
20 buf = prev = ce->hunk->pos; | 28 buf = prev = ce->hunk->pos; |
21 size = 0; | 29 size = 0; |
22 | 30 |
23 /* coalesce the neighbouring chain entries */ | 31 /* coalesce the neighbouring chain entries */ |
32 | |
24 while (ce && prev == ce->hunk->pos) { | 33 while (ce && prev == ce->hunk->pos) { |
25 size += ce->hunk->last - ce->hunk->pos; | 34 size += ce->hunk->last - ce->hunk->pos; |
26 prev = ce->hunk->last; | 35 prev = ce->hunk->last; |
27 ce = ce->next; | 36 ce = ce->next; |
28 } | 37 } |
31 | 40 |
32 #if (NGX_DEBUG_WRITE_CHAIN) | 41 #if (NGX_DEBUG_WRITE_CHAIN) |
33 ngx_log_debug(c->log, "aio_write rc: %d" _ rc); | 42 ngx_log_debug(c->log, "aio_write rc: %d" _ rc); |
34 #endif | 43 #endif |
35 | 44 |
45 if (rc == NGX_ERROR) { | |
46 return NGX_CHAIN_ERROR; | |
47 } | |
48 | |
36 if (rc > 0) { | 49 if (rc > 0) { |
37 sent += rc; | 50 sent += rc; |
38 c->sent += rc; | 51 c->sent += rc; |
52 } | |
39 | 53 |
40 } else if (rc == NGX_ERROR) { | 54 #if (NGX_DEBUG_WRITE_CHAIN) |
41 return NGX_CHAIN_ERROR; | 55 ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent); |
56 #endif | |
42 | 57 |
43 } else if (rc == NGX_AGAIN) { | 58 for (ce = in; ce; ce = ce->next) { |
59 | |
60 if (sent >= ce->hunk->last - ce->hunk->pos) { | |
61 sent -= ce->hunk->last - ce->hunk->pos; | |
62 ce->hunk->pos = ce->hunk->last; | |
63 | |
64 continue; | |
65 } | |
66 | |
67 ce->hunk->pos += sent; | |
68 | |
44 break; | 69 break; |
45 } | 70 } |
46 } | 71 } |
47 | 72 |
48 #if (NGX_DEBUG_WRITE_CHAIN) | |
49 ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent); | |
50 #endif | |
51 | |
52 for (ce = in; ce; ce = ce->next) { | |
53 | |
54 if (sent >= ce->hunk->last - ce->hunk->pos) { | |
55 sent -= ce->hunk->last - ce->hunk->pos; | |
56 ce->hunk->pos = ce->hunk->last; | |
57 | |
58 continue; | |
59 } | |
60 | |
61 ce->hunk->pos += sent; | |
62 | |
63 break; | |
64 } | |
65 | |
66 return ce; | 73 return ce; |
67 } | 74 } |