src/os/win32/ngx_wsasend.c - nginx-1.31.9 nginx/ @ 2a3a19c6f

Functions defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #include <ngx_config.h>
  6. #include <ngx_core.h>
  7. #include <ngx_event.h>


  8. ssize_t
  9. ‌ngx_wsasend(ngx_connection_t *c, u_char *buf, size_t size)
  10. {
  11.     int           n;
  12.     u_long        sent;
  13.     ngx_err_t     err;
  14.     ngx_event_t  *wev;
  15.     WSABUF        wsabuf;

  16.     wev = c->write;

  17.     if (!wev->ready) {
  18.         return NGX_AGAIN;
  19.     }

  20.     /*
  21.      * WSABUF must be 4-byte aligned otherwise
  22.      * WSASend() will return undocumented WSAEINVAL error.
  23.      */

  24.     wsabuf.buf = (char *) buf;
  25.     wsabuf.len = size;

  26.     sent = 0;

  27.     n = WSASend(c->fd, &wsabuf, 1, &sent, 0, NULL, NULL);

  28.     ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
  29.                    "WSASend: fd:%d, %d, %ul of %uz", c->fd, n, sent, size);

  30.     if (n == 0) {
  31.         if (sent < size) {
  32.             wev->ready = 0;
  33.         }

  34.         c->sent += sent;

  35.         return sent;
  36.     }

  37.     err = ngx_socket_errno;

  38.     if (err == WSAEWOULDBLOCK) {
  39.         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, "WSASend() not ready");
  40.         wev->ready = 0;
  41.         return NGX_AGAIN;
  42.     }

  43.     wev->error = 1;
  44.     ngx_connection_error(c, err, "WSASend() failed");

  45.     return NGX_ERROR;
  46. }