Mercurial > hg > nginx
annotate src/os/unix/ngx_udp_recv.c @ 2006:b52cb9bf2064
style fix: remove tabs and trailing spaces
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 May 2008 07:54:52 +0000 |
parents | 0b592a68aade |
children | ac33852faaac |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
5 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
9 #include <ngx_event.h> |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
10 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
469 | 12 #if (NGX_HAVE_KQUEUE) |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
1680 | 14 ssize_t |
1689 | 15 ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 ssize_t n; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
18 ngx_err_t err; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
19 ngx_event_t *rev; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
21 rev = c->read; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
23 do { |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
24 n = recv(c->fd, buf, size, 0); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
26 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
27 "recv: fd:%d %d of %d", c->fd, n, size); |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
28 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
29 if (n >= 0) { |
455 | 30 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
31 rev->available -= n; |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
32 |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
33 /* |
583 | 34 * rev->available may be negative here because some additional |
587 | 35 * bytes may be received between kevent() and recv() |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
36 */ |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
37 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
38 if (rev->available <= 0) { |
1689 | 39 rev->ready = 0; |
605 | 40 rev->available = 0; |
41 } | |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
42 } |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
43 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
44 return n; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
47 err = ngx_socket_errno; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
48 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
49 if (err == NGX_EAGAIN || err == NGX_EINTR) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
50 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
51 "recv() not ready"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
52 n = NGX_AGAIN; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
54 } else { |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
55 n = ngx_connection_error(c, err, "recv() failed"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
56 break; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
57 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
59 } while (err == NGX_EINTR); |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
60 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
61 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
62 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
63 if (n == NGX_ERROR){ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
64 rev->error = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
65 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
66 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 return n; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
69 |
469 | 70 #else /* ! NGX_HAVE_KQUEUE */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
71 |
1680 | 72 ssize_t |
1689 | 73 ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
74 { |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
75 ssize_t n; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
76 ngx_err_t err; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
77 ngx_event_t *rev; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
78 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
79 rev = c->read; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
80 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
81 do { |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
82 n = recv(c->fd, buf, size, 0); |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
83 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
84 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
85 "recv: fd:%d %d of %d", c->fd, n, size); |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
86 |
1689 | 87 if (n >= 0) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
88 return n; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
89 } |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
90 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
91 err = ngx_socket_errno; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
92 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
93 if (err == NGX_EAGAIN || err == NGX_EINTR) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
94 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
95 "recv() not ready"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
96 n = NGX_AGAIN; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
97 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
98 } else { |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
99 n = ngx_connection_error(c, err, "recv() failed"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
100 break; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
101 } |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
102 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
103 } while (err == NGX_EINTR); |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
104 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
105 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
106 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
107 if (n == NGX_ERROR){ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
108 rev->error = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
109 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
110 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
111 return n; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
112 } |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
113 |
469 | 114 #endif /* NGX_HAVE_KQUEUE */ |