mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: h2: add a few functions to retrieve contents from a wrapping buffer
Functions h2_get_buf_n{16,32,64}() and h2_get_buf_bytes() respectively extract a network-ordered 16/32/64 bit value from a possibly wrapping buffer, or any arbitrary size. They're convenient to retrieve a PING payload or to parse SETTINGS frames. Since they copy one byte at a time, they will be less efficient than a memcpy-based implementation on large blocks.
This commit is contained in:
parent
715d5316e5
commit
54c150653d
27
src/mux_h2.c
27
src/mux_h2.c
@ -401,6 +401,33 @@ static inline void h2_set_frame_size(void *frame, uint32_t len)
|
|||||||
write_n16(out + 1, len);
|
write_n16(out + 1, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reads <bytes> bytes from buffer <b> starting at relative offset <o> from the
|
||||||
|
* current pointer, dealing with wrapping, and stores the result in <dst>. It's
|
||||||
|
* the caller's responsibility to verify that there are at least <bytes> bytes
|
||||||
|
* available in the buffer's input prior to calling this function.
|
||||||
|
*/
|
||||||
|
static inline void h2_get_buf_bytes(void *dst, size_t bytes,
|
||||||
|
const struct buffer *b, int o)
|
||||||
|
{
|
||||||
|
readv_bytes(dst, bytes, b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint16_t h2_get_n16(const struct buffer *b, int o)
|
||||||
|
{
|
||||||
|
return readv_n16(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t h2_get_n32(const struct buffer *b, int o)
|
||||||
|
{
|
||||||
|
return readv_n32(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint64_t h2_get_n64(const struct buffer *b, int o)
|
||||||
|
{
|
||||||
|
return readv_n64(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Peeks an H2 frame header from buffer <b> into descriptor <h>. The algorithm
|
/* Peeks an H2 frame header from buffer <b> into descriptor <h>. The algorithm
|
||||||
* is not obvious. It turns out that H2 headers are neither aligned nor do they
|
* is not obvious. It turns out that H2 headers are neither aligned nor do they
|
||||||
* use regular sizes. And to add to the trouble, the buffer may wrap so each
|
* use regular sizes. And to add to the trouble, the buffer may wrap so each
|
||||||
|
Loading…
x
Reference in New Issue
Block a user