Annotation of embedaddon/nginx/src/os/unix/ngx_udp_recv.c, revision 1.1.1.1
1.1 misho 1:
2: /*
3: * Copyright (C) Igor Sysoev
4: * Copyright (C) Nginx, Inc.
5: */
6:
7:
8: #include <ngx_config.h>
9: #include <ngx_core.h>
10: #include <ngx_event.h>
11:
12:
13: #if (NGX_HAVE_KQUEUE)
14:
15: ssize_t
16: ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
17: {
18: ssize_t n;
19: ngx_err_t err;
20: ngx_event_t *rev;
21:
22: rev = c->read;
23:
24: do {
25: n = recv(c->fd, buf, size, 0);
26:
27: ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
28: "recv: fd:%d %d of %d", c->fd, n, size);
29:
30: if (n >= 0) {
31: if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
32: rev->available -= n;
33:
34: /*
35: * rev->available may be negative here because some additional
36: * bytes may be received between kevent() and recv()
37: */
38:
39: if (rev->available <= 0) {
40: rev->ready = 0;
41: rev->available = 0;
42: }
43: }
44:
45: return n;
46: }
47:
48: err = ngx_socket_errno;
49:
50: if (err == NGX_EAGAIN || err == NGX_EINTR) {
51: ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
52: "recv() not ready");
53: n = NGX_AGAIN;
54:
55: } else {
56: n = ngx_connection_error(c, err, "recv() failed");
57: break;
58: }
59:
60: } while (err == NGX_EINTR);
61:
62: rev->ready = 0;
63:
64: if (n == NGX_ERROR) {
65: rev->error = 1;
66: }
67:
68: return n;
69: }
70:
71: #else /* ! NGX_HAVE_KQUEUE */
72:
73: ssize_t
74: ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
75: {
76: ssize_t n;
77: ngx_err_t err;
78: ngx_event_t *rev;
79:
80: rev = c->read;
81:
82: do {
83: n = recv(c->fd, buf, size, 0);
84:
85: ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
86: "recv: fd:%d %d of %d", c->fd, n, size);
87:
88: if (n >= 0) {
89: return n;
90: }
91:
92: err = ngx_socket_errno;
93:
94: if (err == NGX_EAGAIN || err == NGX_EINTR) {
95: ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
96: "recv() not ready");
97: n = NGX_AGAIN;
98:
99: } else {
100: n = ngx_connection_error(c, err, "recv() failed");
101: break;
102: }
103:
104: } while (err == NGX_EINTR);
105:
106: rev->ready = 0;
107:
108: if (n == NGX_ERROR) {
109: rev->error = 1;
110: }
111:
112: return n;
113: }
114:
115: #endif /* NGX_HAVE_KQUEUE */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>