Mercurial > hg > nginx
comparison src/os/unix/ngx_aio_write_chain.c @ 63:36d2c25cc9bb
nginx-0.0.1-2003-02-26-23:21:43 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 26 Feb 2003 20:21:43 +0000 |
parents | |
children | 738fe44c70d5 |
comparison
equal
deleted
inserted
replaced
62:8ccba41a678e | 63:36d2c25cc9bb |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 | |
4 #include <ngx_core.h> | |
5 #include <ngx_types.h> | |
6 #include <ngx_alloc.h> | |
7 #include <ngx_array.h> | |
8 #include <ngx_hunk.h> | |
9 #include <ngx_connection.h> | |
10 #include <ngx_sendv.h> | |
11 #include <ngx_sendfile.h> | |
12 | |
13 | |
14 ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in) | |
15 { | |
16 int rc; | |
17 char *buf, *prev; | |
18 off_t sent; | |
19 size_t size; | |
20 ngx_err_t err; | |
21 ngx_chain_t *ce; | |
22 | |
23 sent = 0; | |
24 ce = in; | |
25 | |
26 while (ce) { | |
27 | |
28 ngx_log_debug(c->log, "aio_write ce: %x" _ ce->hunk->pos.mem); | |
29 | |
30 buf = prev = ce->hunk->pos.mem; | |
31 size = 0; | |
32 | |
33 /* coalesce the neighbouring chain entries */ | |
34 while (ce && prev == ce->hunk->pos.mem) { | |
35 size += ce->hunk->last.mem - ce->hunk->pos.mem; | |
36 prev = ce->hunk->last.mem; | |
37 ce = ce->next; | |
38 } | |
39 | |
40 rc = ngx_event_aio_write(c, buf, size); | |
41 | |
42 ngx_log_debug(c->log, "aio_write rc: %d" _ rc); | |
43 | |
44 if (rc > 0) { | |
45 sent += rc; | |
46 c->sent += rc; | |
47 | |
48 } else if (rc == NGX_ERROR) { | |
49 return NGX_CHAIN_ERROR; | |
50 | |
51 } else if (rc == NGX_AGAIN) { | |
52 break; | |
53 } | |
54 } | |
55 | |
56 #if (NGX_DEBUG_WRITE_CHAIN) | |
57 ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent); | |
58 #endif | |
59 | |
60 for (ce = in; ce; ce = ce->next) { | |
61 | |
62 #if (NGX_DEBUG_WRITE_CHAIN) | |
63 ngx_log_debug(c->log, "write chain: %x %qx %qd" _ | |
64 ce->hunk->type _ | |
65 ce->hunk->pos.file _ | |
66 ce->hunk->last.file - ce->hunk->pos.file); | |
67 #endif | |
68 | |
69 if (sent >= ce->hunk->last.file - ce->hunk->pos.file) { | |
70 sent -= ce->hunk->last.file - ce->hunk->pos.file; | |
71 ce->hunk->pos.file = ce->hunk->last.file; | |
72 | |
73 #if (NGX_DEBUG_WRITE_CHAIN) | |
74 ngx_log_debug(c->log, "write chain done: %qx %qd" _ | |
75 ce->hunk->pos.file _ sent); | |
76 #endif | |
77 continue; | |
78 } | |
79 | |
80 ce->hunk->pos.file += sent; | |
81 | |
82 #if (NGX_DEBUG_WRITE_CHAIN) | |
83 ngx_log_debug(c->log, "write chain rest: %qx %qd" _ | |
84 ce->hunk->pos.file _ | |
85 ce->hunk->last.file - ce->hunk->pos.file); | |
86 #endif | |
87 | |
88 break; | |
89 } | |
90 | |
91 return ce; | |
92 } |