annotate src/event/ngx_event_udp.h @ 9067:f68fdb017141 quic

QUIC: optimized sending stream response. When a stream is created by client, it's often the case that nginx will send immediate response on that stream. An example is HTTP/3 request stream, which in most cases quickly replies with at least HTTP headers. QUIC stream init handlers are called from a posted event. Output QUIC frames are also sent to client from a posted event, called the push event. If the push event is posted before the stream init event, then output produced by stream may trigger sending an extra UDP datagram. To address this, push event is now re-posted when a new stream init event is posted. An example is handling 0-RTT packets. Client typically sends an init packet coalesced with a 0-RTT packet. Previously, nginx replied with a padded CRYPTO datagram, followed by a 1-RTT stream reply datagram. Now CRYPTO and STREAM packets are coalesced in one reply datagram, which saves bandwidth. Other examples include coalescing 1-RTT first stream response, and MAX_STREAMS/STREAM sent in response to ACK/STREAM.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 03 Apr 2023 16:17:12 +0400
parents c2f5d79cde64
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8838
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
2 /*
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
3 * Copyright (C) Nginx, Inc.
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
4 */
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
5
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
6
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
7 #ifndef _NGX_EVENT_UDP_H_INCLUDED_
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
8 #define _NGX_EVENT_UDP_H_INCLUDED_
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
9
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
10
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
11 #include <ngx_config.h>
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
12 #include <ngx_core.h>
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
13
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
14
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
15 #if !(NGX_WIN32)
8839
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
16
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
17 #if ((NGX_HAVE_MSGHDR_MSG_CONTROL) \
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
18 && (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR \
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
19 || NGX_HAVE_IP_PKTINFO \
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
20 || (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)))
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
21 #define NGX_HAVE_ADDRINFO_CMSG 1
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
22
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
23 #endif
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
24
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
25
8510
6f434af59257 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
26 struct ngx_udp_connection_s {
8862
c2f5d79cde64 QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents: 8853
diff changeset
27 ngx_rbtree_node_t node;
c2f5d79cde64 QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents: 8853
diff changeset
28 ngx_connection_t *connection;
c2f5d79cde64 QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents: 8853
diff changeset
29 ngx_buf_t *buffer;
8510
6f434af59257 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
30 };
6f434af59257 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
31
6f434af59257 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
32
8839
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
33 #if (NGX_HAVE_ADDRINFO_CMSG)
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
34
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
35 typedef union {
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
36 #if (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR)
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
37 struct in_addr addr;
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
38 #endif
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
39
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
40 #if (NGX_HAVE_IP_PKTINFO)
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
41 struct in_pktinfo pkt;
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
42 #endif
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
43
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
44 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
45 struct in6_pktinfo pkt6;
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
46 #endif
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
47 } ngx_addrinfo_t;
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
48
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
49 size_t ngx_set_srcaddr_cmsg(struct cmsghdr *cmsg,
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
50 struct sockaddr *local_sockaddr);
8840
0f6cc8f73744 Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents: 8839
diff changeset
51 ngx_int_t ngx_get_srcaddr_cmsg(struct cmsghdr *cmsg,
0f6cc8f73744 Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents: 8839
diff changeset
52 struct sockaddr *local_sockaddr);
8839
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
53
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
54 #endif
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
55
8838
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
56 void ngx_event_recvmsg(ngx_event_t *ev);
8839
cfe1284e5d1d Core: made the ngx_sendmsg() function non-static.
Vladimir Homutov <vl@nginx.com>
parents: 8838
diff changeset
57 ssize_t ngx_sendmsg(ngx_connection_t *c, struct msghdr *msg, int flags);
8838
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
58 void ngx_udp_rbtree_insert_value(ngx_rbtree_node_t *temp,
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
59 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
60 #endif
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
61
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
62 void ngx_delete_udp_connection(void *data);
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
63
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
64
8206ecdcd837 Core: the ngx_event_udp.h header file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
65 #endif /* _NGX_EVENT_UDP_H_INCLUDED_ */