Mercurial > hg > nginx-quic
annotate src/event/ngx_event_udp.c @ 7573:ce2ced385690 release-1.17.4
nginx-1.17.4-RELEASE
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 24 Sep 2019 18:08:48 +0300 |
parents | 6d4bc025c5a7 |
children | 45db1b5c1706 fdc3d40979b0 |
rev | line source |
---|---|
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
1 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
2 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Roman Arutyunyan |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
4 * Copyright (C) Nginx, Inc. |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
5 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
6 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
7 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
11 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
12 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
13 #if !(NGX_WIN32) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
14 |
7286 | 15 struct ngx_udp_connection_s { |
16 ngx_rbtree_node_t node; | |
17 ngx_connection_t *connection; | |
18 ngx_buf_t *buffer; | |
19 }; | |
20 | |
21 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
22 static void ngx_close_accepted_udp_connection(ngx_connection_t *c); |
7286 | 23 static ssize_t ngx_udp_shared_recv(ngx_connection_t *c, u_char *buf, |
24 size_t size); | |
25 static ngx_int_t ngx_insert_udp_connection(ngx_connection_t *c); | |
26 static ngx_connection_t *ngx_lookup_udp_connection(ngx_listening_t *ls, | |
27 struct sockaddr *sockaddr, socklen_t socklen, | |
28 struct sockaddr *local_sockaddr, socklen_t local_socklen); | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
29 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
30 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
31 void |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
32 ngx_event_recvmsg(ngx_event_t *ev) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
33 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
34 ssize_t n; |
7286 | 35 ngx_buf_t buf; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
36 ngx_log_t *log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
37 ngx_err_t err; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
38 socklen_t socklen, local_socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
39 ngx_event_t *rev, *wev; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
40 struct iovec iov[1]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
41 struct msghdr msg; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
42 ngx_sockaddr_t sa, lsa; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
43 struct sockaddr *sockaddr, *local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
44 ngx_listening_t *ls; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
45 ngx_event_conf_t *ecf; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
46 ngx_connection_t *c, *lc; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
47 static u_char buffer[65535]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
48 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
49 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
50 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
51 #if (NGX_HAVE_IP_RECVDSTADDR) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
52 u_char msg_control[CMSG_SPACE(sizeof(struct in_addr))]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
53 #elif (NGX_HAVE_IP_PKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
54 u_char msg_control[CMSG_SPACE(sizeof(struct in_pktinfo))]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
55 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
56 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
57 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
58 u_char msg_control6[CMSG_SPACE(sizeof(struct in6_pktinfo))]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
59 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
60 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
61 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
62 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
63 if (ev->timedout) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
64 if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
65 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
66 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
67 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
68 ev->timedout = 0; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
69 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
70 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
71 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
72 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
73 if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
74 ev->available = ecf->multi_accept; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
75 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
76 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
77 lc = ev->data; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
78 ls = lc->listening; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
79 ev->ready = 0; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
80 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
81 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
82 "recvmsg on %V, ready: %d", &ls->addr_text, ev->available); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
83 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
84 do { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
85 ngx_memzero(&msg, sizeof(struct msghdr)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
86 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
87 iov[0].iov_base = (void *) buffer; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
88 iov[0].iov_len = sizeof(buffer); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
89 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
90 msg.msg_name = &sa; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
91 msg.msg_namelen = sizeof(ngx_sockaddr_t); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
92 msg.msg_iov = iov; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
93 msg.msg_iovlen = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
94 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
95 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
96 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
97 if (ls->wildcard) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
98 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
99 #if (NGX_HAVE_IP_RECVDSTADDR || NGX_HAVE_IP_PKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
100 if (ls->sockaddr->sa_family == AF_INET) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
101 msg.msg_control = &msg_control; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
102 msg.msg_controllen = sizeof(msg_control); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
103 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
104 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
105 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
106 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
107 if (ls->sockaddr->sa_family == AF_INET6) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
108 msg.msg_control = &msg_control6; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
109 msg.msg_controllen = sizeof(msg_control6); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
110 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
111 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
112 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
113 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
114 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
115 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
116 n = recvmsg(lc->fd, &msg, 0); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
117 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
118 if (n == -1) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
119 err = ngx_socket_errno; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
120 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
121 if (err == NGX_EAGAIN) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
122 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
123 "recvmsg() not ready"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
124 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
125 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
126 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
127 ngx_log_error(NGX_LOG_ALERT, ev->log, err, "recvmsg() failed"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
128 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
129 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
130 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
131 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
132 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
133 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
134 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
135 "recvmsg() truncated data"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
136 continue; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
137 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
138 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
139 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
140 sockaddr = msg.msg_name; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
141 socklen = msg.msg_namelen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
142 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
143 if (socklen > (socklen_t) sizeof(ngx_sockaddr_t)) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
144 socklen = sizeof(ngx_sockaddr_t); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
145 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
146 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
147 if (socklen == 0) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
148 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
149 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
150 * on Linux recvmsg() returns zero msg_namelen |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
151 * when receiving packets from unbound AF_UNIX sockets |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
152 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
153 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
154 socklen = sizeof(struct sockaddr); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
155 ngx_memzero(&sa, sizeof(struct sockaddr)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
156 sa.sockaddr.sa_family = ls->sockaddr->sa_family; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
157 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
158 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
159 local_sockaddr = ls->sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
160 local_socklen = ls->socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
161 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
162 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
163 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
164 if (ls->wildcard) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
165 struct cmsghdr *cmsg; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
166 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
167 ngx_memcpy(&lsa, local_sockaddr, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
168 local_sockaddr = &lsa.sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
169 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
170 for (cmsg = CMSG_FIRSTHDR(&msg); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
171 cmsg != NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
172 cmsg = CMSG_NXTHDR(&msg, cmsg)) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
173 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
174 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
175 #if (NGX_HAVE_IP_RECVDSTADDR) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
176 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
177 if (cmsg->cmsg_level == IPPROTO_IP |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
178 && cmsg->cmsg_type == IP_RECVDSTADDR |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
179 && local_sockaddr->sa_family == AF_INET) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
180 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
181 struct in_addr *addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
182 struct sockaddr_in *sin; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
183 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
184 addr = (struct in_addr *) CMSG_DATA(cmsg); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
185 sin = (struct sockaddr_in *) local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
186 sin->sin_addr = *addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
187 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
188 break; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
189 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
190 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
191 #elif (NGX_HAVE_IP_PKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
192 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
193 if (cmsg->cmsg_level == IPPROTO_IP |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
194 && cmsg->cmsg_type == IP_PKTINFO |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
195 && local_sockaddr->sa_family == AF_INET) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
196 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
197 struct in_pktinfo *pkt; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
198 struct sockaddr_in *sin; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
199 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
200 pkt = (struct in_pktinfo *) CMSG_DATA(cmsg); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
201 sin = (struct sockaddr_in *) local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
202 sin->sin_addr = pkt->ipi_addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
203 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
204 break; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
205 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
206 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
207 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
208 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
209 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
210 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
211 if (cmsg->cmsg_level == IPPROTO_IPV6 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
212 && cmsg->cmsg_type == IPV6_PKTINFO |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
213 && local_sockaddr->sa_family == AF_INET6) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
214 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
215 struct in6_pktinfo *pkt6; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
216 struct sockaddr_in6 *sin6; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
217 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
218 pkt6 = (struct in6_pktinfo *) CMSG_DATA(cmsg); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
219 sin6 = (struct sockaddr_in6 *) local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
220 sin6->sin6_addr = pkt6->ipi6_addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
221 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
222 break; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
223 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
224 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
225 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
226 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
227 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
228 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
229 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
230 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
231 |
7286 | 232 c = ngx_lookup_udp_connection(ls, sockaddr, socklen, local_sockaddr, |
233 local_socklen); | |
234 | |
235 if (c) { | |
236 | |
237 #if (NGX_DEBUG) | |
238 if (c->log->log_level & NGX_LOG_DEBUG_EVENT) { | |
239 ngx_log_handler_pt handler; | |
240 | |
241 handler = c->log->handler; | |
242 c->log->handler = NULL; | |
243 | |
244 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
245 "recvmsg: fd:%d n:%z", c->fd, n); | |
246 | |
247 c->log->handler = handler; | |
248 } | |
249 #endif | |
250 | |
251 ngx_memzero(&buf, sizeof(ngx_buf_t)); | |
252 | |
253 buf.pos = buffer; | |
254 buf.last = buffer + n; | |
255 | |
256 rev = c->read; | |
257 | |
258 c->udp->buffer = &buf; | |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
259 |
7286 | 260 rev->ready = 1; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
261 rev->active = 0; |
7286 | 262 |
263 rev->handler(rev); | |
264 | |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
265 if (c->udp) { |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
266 c->udp->buffer = NULL; |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
267 } |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
268 |
7286 | 269 rev->ready = 0; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
270 rev->active = 1; |
7286 | 271 |
272 goto next; | |
273 } | |
274 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
275 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
276 (void) ngx_atomic_fetch_add(ngx_stat_accepted, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
277 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
278 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
279 ngx_accept_disabled = ngx_cycle->connection_n / 8 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
280 - ngx_cycle->free_connection_n; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
281 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
282 c = ngx_get_connection(lc->fd, ev->log); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
283 if (c == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
284 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
285 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
286 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
287 c->shared = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
288 c->type = SOCK_DGRAM; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
289 c->socklen = socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
290 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
291 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
292 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
293 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
294 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
295 c->pool = ngx_create_pool(ls->pool_size, ev->log); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
296 if (c->pool == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
297 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
298 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
299 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
300 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
301 c->sockaddr = ngx_palloc(c->pool, socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
302 if (c->sockaddr == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
303 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
304 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
305 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
306 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
307 ngx_memcpy(c->sockaddr, sockaddr, socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
308 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
309 log = ngx_palloc(c->pool, sizeof(ngx_log_t)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
310 if (log == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
311 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
312 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
313 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
314 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
315 *log = ls->log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
316 |
7286 | 317 c->recv = ngx_udp_shared_recv; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
318 c->send = ngx_udp_send; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
319 c->send_chain = ngx_udp_send_chain; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
320 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
321 c->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
322 c->pool->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
323 c->listening = ls; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
324 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
325 if (local_sockaddr == &lsa.sockaddr) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
326 local_sockaddr = ngx_palloc(c->pool, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
327 if (local_sockaddr == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
328 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
329 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
330 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
331 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
332 ngx_memcpy(local_sockaddr, &lsa, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
333 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
334 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
335 c->local_sockaddr = local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
336 c->local_socklen = local_socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
337 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
338 c->buffer = ngx_create_temp_buf(c->pool, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
339 if (c->buffer == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
340 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
341 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
342 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
343 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
344 c->buffer->last = ngx_cpymem(c->buffer->last, buffer, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
345 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
346 rev = c->read; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
347 wev = c->write; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
348 |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
349 rev->active = 1; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
350 wev->ready = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
351 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
352 rev->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
353 wev->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
354 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
355 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
356 * TODO: MT: - ngx_atomic_fetch_add() |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
357 * or protection by critical section or light mutex |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
358 * |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
359 * TODO: MP: - allocated in a shared memory |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
360 * - ngx_atomic_fetch_add() |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
361 * or protection by critical section or light mutex |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
362 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
363 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
364 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
365 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
366 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
367 (void) ngx_atomic_fetch_add(ngx_stat_handled, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
368 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
369 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
370 if (ls->addr_ntop) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
371 c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
372 if (c->addr_text.data == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
373 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
374 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
375 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
376 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
377 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
378 c->addr_text.data, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
379 ls->addr_text_max_len, 0); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
380 if (c->addr_text.len == 0) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
381 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
382 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
383 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
384 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
385 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
386 #if (NGX_DEBUG) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
387 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
388 ngx_str_t addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
389 u_char text[NGX_SOCKADDR_STRLEN]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
390 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
391 ngx_debug_accepted_connection(ecf, c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
392 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
393 if (log->log_level & NGX_LOG_DEBUG_EVENT) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
394 addr.data = text; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
395 addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
396 NGX_SOCKADDR_STRLEN, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
397 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
398 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
399 "*%uA recvmsg: %V fd:%d n:%z", |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
400 c->number, &addr, c->fd, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
401 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
402 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
403 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
404 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
405 |
7286 | 406 if (ngx_insert_udp_connection(c) != NGX_OK) { |
407 ngx_close_accepted_udp_connection(c); | |
408 return; | |
409 } | |
410 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
411 log->data = NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
412 log->handler = NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
413 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
414 ls->handler(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
415 |
7286 | 416 next: |
417 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
418 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
419 ev->available -= n; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
420 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
421 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
422 } while (ev->available); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
423 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
424 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
425 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
426 static void |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
427 ngx_close_accepted_udp_connection(ngx_connection_t *c) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
428 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
429 ngx_free_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
430 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
431 c->fd = (ngx_socket_t) -1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
432 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
433 if (c->pool) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
434 ngx_destroy_pool(c->pool); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
435 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
436 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
437 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
438 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
439 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
440 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
441 |
7286 | 442 |
443 static ssize_t | |
444 ngx_udp_shared_recv(ngx_connection_t *c, u_char *buf, size_t size) | |
445 { | |
446 ssize_t n; | |
447 ngx_buf_t *b; | |
448 | |
449 if (c->udp == NULL || c->udp->buffer == NULL) { | |
450 return NGX_AGAIN; | |
451 } | |
452 | |
453 b = c->udp->buffer; | |
454 | |
455 n = ngx_min(b->last - b->pos, (ssize_t) size); | |
456 | |
457 ngx_memcpy(buf, b->pos, n); | |
458 | |
459 c->udp->buffer = NULL; | |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
460 |
7286 | 461 c->read->ready = 0; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
462 c->read->active = 1; |
7286 | 463 |
464 return n; | |
465 } | |
466 | |
467 | |
468 void | |
469 ngx_udp_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
470 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
471 { | |
472 ngx_int_t rc; | |
473 ngx_connection_t *c, *ct; | |
474 ngx_rbtree_node_t **p; | |
475 ngx_udp_connection_t *udp, *udpt; | |
476 | |
477 for ( ;; ) { | |
478 | |
479 if (node->key < temp->key) { | |
480 | |
481 p = &temp->left; | |
482 | |
483 } else if (node->key > temp->key) { | |
484 | |
485 p = &temp->right; | |
486 | |
487 } else { /* node->key == temp->key */ | |
488 | |
489 udp = (ngx_udp_connection_t *) node; | |
490 c = udp->connection; | |
491 | |
492 udpt = (ngx_udp_connection_t *) temp; | |
493 ct = udpt->connection; | |
494 | |
495 rc = ngx_cmp_sockaddr(c->sockaddr, c->socklen, | |
496 ct->sockaddr, ct->socklen, 1); | |
497 | |
498 if (rc == 0 && c->listening->wildcard) { | |
499 rc = ngx_cmp_sockaddr(c->local_sockaddr, c->local_socklen, | |
500 ct->local_sockaddr, ct->local_socklen, 1); | |
501 } | |
502 | |
503 p = (rc < 0) ? &temp->left : &temp->right; | |
504 } | |
505 | |
506 if (*p == sentinel) { | |
507 break; | |
508 } | |
509 | |
510 temp = *p; | |
511 } | |
512 | |
513 *p = node; | |
514 node->parent = temp; | |
515 node->left = sentinel; | |
516 node->right = sentinel; | |
517 ngx_rbt_red(node); | |
518 } | |
519 | |
520 | |
521 static ngx_int_t | |
522 ngx_insert_udp_connection(ngx_connection_t *c) | |
523 { | |
524 uint32_t hash; | |
525 ngx_pool_cleanup_t *cln; | |
526 ngx_udp_connection_t *udp; | |
527 | |
528 if (c->udp) { | |
529 return NGX_OK; | |
530 } | |
531 | |
532 udp = ngx_pcalloc(c->pool, sizeof(ngx_udp_connection_t)); | |
533 if (udp == NULL) { | |
534 return NGX_ERROR; | |
535 } | |
536 | |
537 udp->connection = c; | |
538 | |
539 ngx_crc32_init(hash); | |
540 ngx_crc32_update(&hash, (u_char *) c->sockaddr, c->socklen); | |
541 | |
542 if (c->listening->wildcard) { | |
543 ngx_crc32_update(&hash, (u_char *) c->local_sockaddr, c->local_socklen); | |
544 } | |
545 | |
546 ngx_crc32_final(hash); | |
547 | |
548 udp->node.key = hash; | |
549 | |
550 cln = ngx_pool_cleanup_add(c->pool, 0); | |
551 if (cln == NULL) { | |
552 return NGX_ERROR; | |
553 } | |
554 | |
555 cln->data = c; | |
556 cln->handler = ngx_delete_udp_connection; | |
557 | |
558 ngx_rbtree_insert(&c->listening->rbtree, &udp->node); | |
559 | |
560 c->udp = udp; | |
561 | |
562 return NGX_OK; | |
563 } | |
564 | |
565 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
566 void |
7286 | 567 ngx_delete_udp_connection(void *data) |
568 { | |
569 ngx_connection_t *c = data; | |
570 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
571 if (c->udp == NULL) { |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
572 return; |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
573 } |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
574 |
7286 | 575 ngx_rbtree_delete(&c->listening->rbtree, &c->udp->node); |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
576 |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
577 c->udp = NULL; |
7286 | 578 } |
579 | |
580 | |
581 static ngx_connection_t * | |
582 ngx_lookup_udp_connection(ngx_listening_t *ls, struct sockaddr *sockaddr, | |
583 socklen_t socklen, struct sockaddr *local_sockaddr, socklen_t local_socklen) | |
584 { | |
585 uint32_t hash; | |
586 ngx_int_t rc; | |
587 ngx_connection_t *c; | |
588 ngx_rbtree_node_t *node, *sentinel; | |
589 ngx_udp_connection_t *udp; | |
590 | |
591 #if (NGX_HAVE_UNIX_DOMAIN) | |
592 | |
593 if (sockaddr->sa_family == AF_UNIX) { | |
594 struct sockaddr_un *saun = (struct sockaddr_un *) sockaddr; | |
595 | |
596 if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path) | |
597 || saun->sun_path[0] == '\0') | |
598 { | |
599 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, | |
600 "unbound unix socket"); | |
601 return NULL; | |
602 } | |
603 } | |
604 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
605 #endif |
7286 | 606 |
607 node = ls->rbtree.root; | |
608 sentinel = ls->rbtree.sentinel; | |
609 | |
610 ngx_crc32_init(hash); | |
611 ngx_crc32_update(&hash, (u_char *) sockaddr, socklen); | |
612 | |
613 if (ls->wildcard) { | |
614 ngx_crc32_update(&hash, (u_char *) local_sockaddr, local_socklen); | |
615 } | |
616 | |
617 ngx_crc32_final(hash); | |
618 | |
619 while (node != sentinel) { | |
620 | |
621 if (hash < node->key) { | |
622 node = node->left; | |
623 continue; | |
624 } | |
625 | |
626 if (hash > node->key) { | |
627 node = node->right; | |
628 continue; | |
629 } | |
630 | |
631 /* hash == node->key */ | |
632 | |
633 udp = (ngx_udp_connection_t *) node; | |
634 | |
635 c = udp->connection; | |
636 | |
637 rc = ngx_cmp_sockaddr(sockaddr, socklen, | |
638 c->sockaddr, c->socklen, 1); | |
639 | |
640 if (rc == 0 && ls->wildcard) { | |
641 rc = ngx_cmp_sockaddr(local_sockaddr, local_socklen, | |
642 c->local_sockaddr, c->local_socklen, 1); | |
643 } | |
644 | |
645 if (rc == 0) { | |
646 return c; | |
647 } | |
648 | |
649 node = (rc < 0) ? node->left : node->right; | |
650 } | |
651 | |
652 return NULL; | |
653 } | |
654 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
655 #else |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
656 |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
657 void |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
658 ngx_delete_udp_connection(void *data) |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
659 { |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
660 return; |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
661 } |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
662 |
7286 | 663 #endif |