summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2020-03-04 23:24:51 +0300
committerVladimir Homutov <vl@nginx.com>2020-03-04 23:24:51 +0300
commite3e5e21ed53eac32b84e808cb92c0731176a466a (patch)
tree956fdc4ddbc25369831c570e89174871c8ce5c28 /src
parent941d4f1c2ebd6da06fcbda24a71c974166024ef3 (diff)
downloadnginx-e3e5e21ed53eac32b84e808cb92c0731176a466a.tar.gz
nginx-e3e5e21ed53eac32b84e808cb92c0731176a466a.tar.bz2
Macro for calculating size of varint.
Diffstat (limited to 'src')
-rw-r--r--src/event/ngx_event_quic.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/event/ngx_event_quic.c b/src/event/ngx_event_quic.c
index ee8a0c716..f3035dd70 100644
--- a/src/event/ngx_event_quic.c
+++ b/src/event/ngx_event_quic.c
@@ -49,6 +49,8 @@
#define ngx_quic_write_uint32_aligned(p, s) \
(*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
+#define ngx_quic_varint_len(value) \
+ ((value) <= 63 ? 1 : (value) <= 16383 ? 2 : (value) <= 1073741823 ? 4 : 8)
#if (NGX_DEBUG)
@@ -349,12 +351,7 @@ ngx_quic_create_crypto(u_char *p, ngx_quic_crypto_frame_t *crypto)
u_char *start;
if (p == NULL) {
- if (crypto->len >= 64) {
- return crypto->len + 4;
-
- } else {
- return crypto->len + 3;
- } // TODO: proper calculation of varint
+ return 3 + ngx_quic_varint_len(crypto->len) + crypto->len;
}
start = p;