Mercurial > hg > nginx
annotate src/os/win32/ngx_wsasend_chain.c @ 3369:479468a7d982
fix handling cached HTTP/0.9 response
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 29 Nov 2009 20:48:01 +0000 |
parents | 88987e52be42 |
children | d620f497c50f |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
363
diff
changeset
|
5 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
461 | 12 #define NGX_WSABUFS 8 |
13 | |
14 | |
501 | 15 ngx_chain_t * |
16 ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) | |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
18 int rc; |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
19 u_char *prev; |
473 | 20 u_long size, sent, send, prev_send; |
461 | 21 ngx_uint_t complete; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
22 ngx_err_t err; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
23 ngx_event_t *wev; |
461 | 24 ngx_array_t vec; |
501 | 25 ngx_chain_t *cl; |
461 | 26 LPWSABUF wsabuf; |
27 WSABUF wsabufs[NGX_WSABUFS]; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
28 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
29 wev = c->write; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
30 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
31 if (!wev->ready) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
32 return in; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
33 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
34 |
473 | 35 /* the maximum limit size is the maximum u_long value - the page size */ |
36 | |
37 if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) { | |
38 limit = NGX_MAX_UINT32_VALUE - ngx_pagesize; | |
39 } | |
40 | |
461 | 41 send = 0; |
42 complete = 0; | |
43 | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
44 /* |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
45 * WSABUFs must be 4-byte aligned otherwise |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
46 * WSASend() will return undocumented WSAEINVAL error. |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
47 */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
48 |
461 | 49 vec.elts = wsabufs; |
50 vec.size = sizeof(WSABUF); | |
577 | 51 vec.nalloc = NGX_WSABUFS; |
461 | 52 vec.pool = c->pool; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
53 |
461 | 54 for ( ;; ) { |
55 prev = NULL; | |
56 wsabuf = NULL; | |
473 | 57 prev_send = send; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
58 |
461 | 59 vec.nelts = 0; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
60 |
461 | 61 /* create the WSABUF and coalesce the neighbouring bufs */ |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
62 |
461 | 63 for (cl = in; |
64 cl && vec.nelts < ngx_max_wsabufs && send < limit; | |
65 cl = cl->next) | |
66 { | |
67 if (ngx_buf_special(cl->buf)) { | |
68 continue; | |
69 } | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
70 |
461 | 71 size = cl->buf->last - cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
72 |
461 | 73 if (send + size > limit) { |
74 size = (u_long) (limit - send); | |
75 } | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
76 |
461 | 77 if (prev == cl->buf->pos) { |
78 wsabuf->len += cl->buf->last - cl->buf->pos; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
79 |
461 | 80 } else { |
501 | 81 wsabuf = ngx_array_push(&vec); |
82 if (wsabuf == NULL) { | |
461 | 83 return NGX_CHAIN_ERROR; |
84 } | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
85 |
461 | 86 wsabuf->buf = (char *) cl->buf->pos; |
87 wsabuf->len = cl->buf->last - cl->buf->pos; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
88 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
89 |
461 | 90 prev = cl->buf->last; |
91 send += size; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
92 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
93 |
461 | 94 sent = 0; |
95 | |
96 rc = WSASend(c->fd, vec.elts, vec.nelts, &sent, 0, NULL, NULL); | |
97 | |
98 if (rc == -1) { | |
99 err = ngx_errno; | |
100 | |
101 if (err == WSAEWOULDBLOCK) { | |
102 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, | |
103 "WSASend() not ready"); | |
104 | |
105 } else { | |
106 wev->error = 1; | |
107 ngx_connection_error(c, err, "WSASend() failed"); | |
108 return NGX_CHAIN_ERROR; | |
109 } | |
110 } | |
111 | |
112 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
113 "WSASend: fd:%d, s:%ul", c->fd, sent); | |
114 | |
473 | 115 if (send - prev_send == sent) { |
461 | 116 complete = 1; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
117 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
118 |
461 | 119 c->sent += sent; |
120 | |
2614 | 121 for (cl = in; cl; cl = cl->next) { |
122 | |
461 | 123 if (ngx_buf_special(cl->buf)) { |
124 continue; | |
125 } | |
126 | |
127 if (sent == 0) { | |
128 break; | |
129 } | |
130 | |
131 size = cl->buf->last - cl->buf->pos; | |
132 | |
133 if (sent >= size) { | |
134 sent -= size; | |
135 cl->buf->pos = cl->buf->last; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
136 |
461 | 137 continue; |
138 } | |
139 | |
140 cl->buf->pos += sent; | |
141 | |
142 break; | |
143 } | |
144 | |
145 if (!complete) { | |
146 wev->ready = 0; | |
147 return cl; | |
148 } | |
149 | |
150 if (send >= limit || cl == NULL) { | |
151 return cl; | |
152 } | |
153 | |
154 in = cl; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
155 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
156 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
157 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
158 |
501 | 159 ngx_chain_t * |
160 ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
161 { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
162 int rc; |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
163 u_char *prev; |
473 | 164 u_long size, send, sent; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
165 ngx_err_t err; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
166 ngx_event_t *wev; |
461 | 167 ngx_array_t vec; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
168 ngx_chain_t *cl; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
169 LPWSAOVERLAPPED ovlp; |
501 | 170 LPWSABUF wsabuf; |
461 | 171 WSABUF wsabufs[NGX_WSABUFS]; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
172 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
173 wev = c->write; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
174 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
175 if (!wev->ready) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
176 return in; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
177 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
178 |
461 | 179 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
180 "wev->complete: %d", wev->complete); | |
181 | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
182 if (!wev->complete) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
183 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
184 /* post the overlapped WSASend() */ |
473 | 185 |
186 /* the maximum limit size is the maximum u_long value - the page size */ | |
187 | |
188 if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) { | |
189 limit = NGX_MAX_UINT32_VALUE - ngx_pagesize; | |
190 } | |
577 | 191 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
192 /* |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
193 * WSABUFs must be 4-byte aligned otherwise |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
194 * WSASend() will return undocumented WSAEINVAL error. |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
195 */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
196 |
461 | 197 vec.elts = wsabufs; |
198 vec.nelts = 0; | |
199 vec.size = sizeof(WSABUF); | |
577 | 200 vec.nalloc = NGX_WSABUFS; |
461 | 201 vec.pool = c->pool; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
202 |
461 | 203 send = 0; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
204 prev = NULL; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
205 wsabuf = NULL; |
577 | 206 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
207 /* create the WSABUF and coalesce the neighbouring bufs */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
208 |
461 | 209 for (cl = in; |
210 cl && vec.nelts < ngx_max_wsabufs && send < limit; | |
211 cl = cl->next) | |
212 { | |
213 if (ngx_buf_special(cl->buf)) { | |
214 continue; | |
215 } | |
216 | |
217 size = cl->buf->last - cl->buf->pos; | |
218 | |
219 if (send + size > limit) { | |
220 size = (u_long) (limit - send); | |
221 } | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
222 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
223 if (prev == cl->buf->pos) { |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
224 wsabuf->len += cl->buf->last - cl->buf->pos; |
461 | 225 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
226 } else { |
501 | 227 wsabuf = ngx_array_push(&vec); |
228 if (wsabuf == NULL) { | |
461 | 229 return NGX_CHAIN_ERROR; |
230 } | |
231 | |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
232 wsabuf->buf = (char *) cl->buf->pos; |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
233 wsabuf->len = cl->buf->last - cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
234 } |
461 | 235 |
236 prev = cl->buf->last; | |
237 send += size; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
238 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
239 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
240 ovlp = (LPWSAOVERLAPPED) &c->write->ovlp; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
241 ngx_memzero(ovlp, sizeof(WSAOVERLAPPED)); |
577 | 242 |
461 | 243 rc = WSASend(c->fd, vec.elts, vec.nelts, &sent, 0, ovlp, NULL); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
244 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
245 wev->complete = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
246 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
247 if (rc == -1) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
248 err = ngx_errno; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
249 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
250 if (err == WSA_IO_PENDING) { |
461 | 251 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
252 "WSASend() posted"); | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
253 wev->active = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
254 return in; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
255 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
256 } else { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
257 wev->error = 1; |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
258 ngx_connection_error(c, err, "WSASend() failed"); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
259 return NGX_CHAIN_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
260 } |
577 | 261 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
262 } else if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
263 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
264 /* |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
265 * if a socket was bound with I/O completion port then |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
266 * GetQueuedCompletionStatus() would anyway return its status |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
267 * despite that WSASend() was already complete |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
268 */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
269 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
270 wev->active = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
271 return in; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
272 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
273 |
461 | 274 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
275 "WSASend: fd:%d, s:%ul", c->fd, sent); | |
276 | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
277 } else { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
278 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
279 /* the overlapped WSASend() complete */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
280 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
281 wev->complete = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
282 wev->active = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
283 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
284 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
285 if (wev->ovlp.error) { |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
286 ngx_connection_error(c, wev->ovlp.error, "WSASend() failed"); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
287 return NGX_CHAIN_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
288 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
289 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
290 sent = wev->available; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
291 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
292 } else { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
293 if (WSAGetOverlappedResult(c->fd, (LPWSAOVERLAPPED) &wev->ovlp, |
2776 | 294 &sent, 0, NULL) |
295 == 0) | |
296 { | |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
297 ngx_connection_error(c, ngx_socket_errno, |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
298 "WSASend() or WSAGetOverlappedResult() failed"); |
577 | 299 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
300 return NGX_CHAIN_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
301 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
302 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
303 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
304 |
461 | 305 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
306 "WSASend ovlp: fd:%d, s:%ul", c->fd, sent); | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
307 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
308 c->sent += sent; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
309 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
310 for (cl = in; cl && sent > 0; cl = cl->next) { |
461 | 311 if (ngx_buf_special(cl->buf)) { |
312 continue; | |
313 } | |
314 | |
315 if (sent == 0) { | |
316 break; | |
317 } | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
318 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
319 size = cl->buf->last - cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
320 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
321 if (sent >= size) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
322 sent -= size; |
461 | 323 cl->buf->pos = cl->buf->last; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
324 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
325 continue; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
326 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
327 |
461 | 328 cl->buf->pos += sent; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
329 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
330 break; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
331 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
332 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
333 if (cl) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
334 wev->ready = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
335 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
336 } else { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
337 wev->ready = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
338 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
339 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
340 return cl; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
341 } |