comparison src/event/ngx_event_quic_transport.c @ 8671:5247461c17e1 quic

QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 22 Dec 2020 12:04:16 +0300
parents 2dfc5ef29973
children
comparison
equal deleted inserted replaced
8670:b14338acbf9d 8671:5247461c17e1
53 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t)) 53 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
54 54
55 #define ngx_quic_write_uint32_aligned(p, s) \ 55 #define ngx_quic_write_uint32_aligned(p, s) \
56 (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t)) 56 (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
57 57
58 #define ngx_quic_varint_len(value) \
59 ((value) <= 63 ? 1 \
60 : ((uint32_t) value) <= 16383 ? 2 \
61 : ((uint64_t) value) <= 1073741823 ? 4 \
62 : 8)
63
64 #define NGX_QUIC_VERSION(c) (0xff000000 + (c)) 58 #define NGX_QUIC_VERSION(c) (0xff000000 + (c))
65 59
66 60
67 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out); 61 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out);
62 static ngx_uint_t ngx_quic_varint_len(uint64_t value);
68 static void ngx_quic_build_int(u_char **pos, uint64_t value); 63 static void ngx_quic_build_int(u_char **pos, uint64_t value);
69 64
70 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value); 65 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value);
71 static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value); 66 static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value);
72 static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len, 67 static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len,
231 } 226 }
232 227
233 ngx_memcpy(dst, pos, len); 228 ngx_memcpy(dst, pos, len);
234 229
235 return pos + len; 230 return pos + len;
231 }
232
233
234 static ngx_uint_t
235 ngx_quic_varint_len(uint64_t value)
236 {
237 ngx_uint_t bits;
238
239 bits = 0;
240 while (value >> ((8 << bits) - 2)) {
241 bits++;
242 }
243
244 return 1 << bits;
236 } 245 }
237 246
238 247
239 static void 248 static void
240 ngx_quic_build_int(u_char **pos, uint64_t value) 249 ngx_quic_build_int(u_char **pos, uint64_t value)