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_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
0015 {
0016     ssize_t       n;
0017     ngx_err_t     err;
0018     ngx_event_t  *rev;
0019 
0020     rev = c->read;
0021 
0022     do {
0023         n = recv(c->fd, buf, size, 0);
0024 
0025         ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
0026                        "recv: fd:%d %z of %uz", c->fd, n, size);
0027 
0028         if (n >= 0) {
0029 
0030 #if (NGX_HAVE_KQUEUE)
0031 
0032             if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
0033                 rev->available -= n;
0034 
0035                 /*
0036                  * rev->available may be negative here because some additional
0037                  * bytes may be received between kevent() and recv()
0038                  */
0039 
0040                 if (rev->available <= 0) {
0041                     rev->ready = 0;
0042                     rev->available = 0;
0043                 }
0044             }
0045 
0046 #endif
0047 
0048             return n;
0049         }
0050 
0051         err = ngx_socket_errno;
0052 
0053         if (err == NGX_EAGAIN || err == NGX_EINTR) {
0054             ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
0055                            "recv() not ready");
0056             n = NGX_AGAIN;
0057 
0058         } else {
0059             n = ngx_connection_error(c, err, "recv() failed");
0060             break;
0061         }
0062 
0063     } while (err == NGX_EINTR);
0064 
0065     rev->ready = 0;
0066 
0067     if (n == NGX_ERROR) {
0068         rev->error = 1;
0069     }
0070 
0071     return n;
0072 }