Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 #include <ngx_event.h>
0011 
0012 
0013 ssize_t
0014 ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size)
0015 {
0016     ssize_t       n;
0017     ngx_err_t     err;
0018     ngx_event_t  *wev;
0019 
0020     wev = c->write;
0021 
0022 #if (NGX_HAVE_KQUEUE)
0023 
0024     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) {
0025         (void) ngx_connection_error(c, wev->kq_errno,
0026                                "kevent() reported about an closed connection");
0027         wev->error = 1;
0028         return NGX_ERROR;
0029     }
0030 
0031 #endif
0032 
0033     for ( ;; ) {
0034         n = send(c->fd, buf, size, 0);
0035 
0036         ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
0037                        "send: fd:%d %z of %uz", c->fd, n, size);
0038 
0039         if (n > 0) {
0040             if (n < (ssize_t) size) {
0041                 wev->ready = 0;
0042             }
0043 
0044             c->sent += n;
0045 
0046             return n;
0047         }
0048 
0049         err = ngx_socket_errno;
0050 
0051         if (n == 0) {
0052             ngx_log_error(NGX_LOG_ALERT, c->log, err, "send() returned zero");
0053             wev->ready = 0;
0054             return n;
0055         }
0056 
0057         if (err == NGX_EAGAIN || err == NGX_EINTR) {
0058             wev->ready = 0;
0059 
0060             ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
0061                            "send() not ready");
0062 
0063             if (err == NGX_EAGAIN) {
0064                 return NGX_AGAIN;
0065             }
0066 
0067         } else {
0068             wev->error = 1;
0069             (void) ngx_connection_error(c, err, "send() failed");
0070             return NGX_ERROR;
0071         }
0072     }
0073 }