comparison src/os/win32/ngx_wsasend_chain.c @ 344:e366ba5db8f8

nginx-0.0.3-2004-06-01-10:04:46 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 01 Jun 2004 06:04:46 +0000
parents 6bdf858bff8c
children f2755a2885c8
comparison
equal deleted inserted replaced
343:6bdf858bff8c 344:e366ba5db8f8
239 wev->ready = 1; 239 wev->ready = 1;
240 } 240 }
241 241
242 return cl; 242 return cl;
243 } 243 }
244
245
246 #if 0
247
248 ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in)
249 {
250 int rc;
251 char *prev;
252 size_t size, sent;
253 LPWSABUF wsabuf;
254 ngx_err_t err;
255 ngx_event_t *wev;
256 ngx_array_t wsabufs;
257 ngx_chain_t *ce;
258 LPWSAOVERLAPPED ovlp;
259
260 #if 0
261
262 iocp:
263 if ready
264 get result
265 update chain
266 return if done;
267 wsasend
268
269 non-block
270 for ( ;; ) {
271 wsasend
272 if no again
273 update chain
274 return if done;
275 }
276
277
278 for ( ;; ) {
279
280 make buffers and limit data for both ovlp and nonblocked,
281 configured in events module
282
283 if (iocp && ready) {
284 get result
285
286 } else {
287 if (file)
288 transmitfile
289 else
290 wsasend
291
292 if (iocp)
293 return chain
294 return chain if again
295 here is result
296 }
297
298 if (result)
299 update chain;
300 return chain if done
301 }
302 }
303
304
305 #endif
306
307 wev = c->write;
308
309 if (((ngx_event_flags & NGX_USE_AIO_EVENT) && !wev->ready)
310 || ((ngx_event_flags & NGX_USE_AIO_EVENT) == 0))
311 {
312 /*
313 * WSABUFs must be 4-byte aligned otherwise
314 * WSASend() will return undocumented WSAEINVAL error.
315 */
316
317 ngx_init_array(wsabufs, c->pool, 10, sizeof(WSABUF), NGX_CHAIN_ERROR);
318
319 prev = NULL;
320 wsabuf = NULL;
321
322 /* create the WSABUF and coalesce the neighbouring chain entries */
323 for (ce = in; ce; ce = ce->next) {
324
325 if (prev == ce->hunk->pos) {
326 wsabuf->len += ce->hunk->last - ce->hunk->pos;
327 prev = ce->hunk->last;
328
329 } else {
330 ngx_test_null(wsabuf, ngx_push_array(&wsabufs),
331 NGX_CHAIN_ERROR);
332 wsabuf->buf = ce->hunk->pos;
333 wsabuf->len = ce->hunk->last - ce->hunk->pos;
334 prev = ce->hunk->last;
335 }
336 }
337
338 if (ngx_event_flags & NGX_USE_AIO_EVENT) {
339 ovlp = (LPWSAOVERLAPPED) &c->write->ovlp;
340 ngx_memzero(ovlp, sizeof(WSAOVERLAPPED));
341
342 } else {
343 ovlp = NULL;
344 }
345
346 rc = WSASend(c->fd, wsabufs.elts, wsabufs.nelts, &sent, 0, ovlp, NULL);
347
348 if (rc == -1) {
349 err = ngx_errno;
350 if (err == WSA_IO_PENDING) {
351 sent = 0;
352
353 } else if (err == WSAEWOULDBLOCK) {
354 sent = 0;
355 ngx_log_error(NGX_LOG_INFO, c->log, err, "WSASend() EAGAIN");
356
357 } else {
358 ngx_log_error(NGX_LOG_CRIT, c->log, err, "WSASend() failed");
359 return NGX_CHAIN_ERROR;
360 }
361
362 } else {
363
364 if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
365
366 /*
367 * If a socket was bound with I/O completion port then
368 * GetQueuedCompletionStatus() would anyway return its status
369 * despite that WSASend() was already completed.
370 */
371
372 sent = 0;
373 }
374 }
375
376 } else {
377 if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
378 wev->ready = 0;
379
380 /* the overlapped WSASend() completed */
381
382 if (wev->ovlp.error) {
383 ngx_log_error(NGX_LOG_ERR, c->log, wev->ovlp.error,
384 "WSASend() failed");
385 return NGX_CHAIN_ERROR;
386 }
387
388 sent = wev->available;
389 }
390 }
391
392 ngx_log_debug(c->log, "WSASend(): %d" _ sent);
393
394 c->sent += sent;
395
396 for (ce = in; ce && sent > 0; ce = ce->next) {
397
398 size = ce->hunk->last - ce->hunk->pos;
399
400 if (sent >= size) {
401 sent -= size;
402
403 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
404 ce->hunk->pos = ce->hunk->last;
405 }
406
407 continue;
408 }
409
410 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
411 ce->hunk->pos += sent;
412 }
413
414 break;
415 }
416
417 return ce;
418 }
419
420 #endif