1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_hpi.h - HPI: (Extensible) HTTP Priority Iterator 4 * 5 * https://tools.ietf.org/html/draft-ietf-httpbis-priority-01 6 * 7 * Changing a stream's priority when the stream is in the iterator 8 * does not change the stream's position in the iterator. 9 */ 10 11#ifndef LSQUIC_HPI 12#define LSQUIC_HPI 1 13 14#ifndef LSQUIC_TEST 15#define LSQUIC_TEST 0 16#endif 17 18struct lsquic_conn_public; 19 20/* We add 1 to the urgency when we place them on hpi_streams. Critical 21 * streams get the highest-priority slot zero. 22 */ 23#define N_HPI_PRIORITIES (2 + LSQUIC_MAX_HTTP_URGENCY) 24 25 26struct http_prio_iter 27{ 28 const char *hpi_name; /* Used for logging */ 29 struct lsquic_conn_public *hpi_conn_pub; 30 enum { 31 HPI_MH_4K = 1 << 0, 32 HPI_MH_MALLOC = 1 << 1, 33 } hpi_flags; 34 unsigned hpi_set[2]; /* Bitmask */ 35 unsigned hpi_counts[N_HPI_PRIORITIES]; /* For non-incr only */ 36 unsigned hpi_heaped; /* Bitmask */ 37 struct lsquic_streams_tailq hpi_streams[2][N_HPI_PRIORITIES]; 38 struct min_heap hpi_min_heap; 39 /* We do this because http_prio_iter is used in a union with 40 * stream_prio_iter, which is over 4KB on the stack. Since we 41 * are already allocating this memory on the stack, we might as well 42 * use it. 43 */ 44 struct min_heap_elem hpi_min_heap_els[236]; 45}; 46 47 48void 49lsquic_hpi_init (void *, struct lsquic_stream *first, 50 struct lsquic_stream *last, uintptr_t next_ptr_offset, 51 struct lsquic_conn_public *, const char *name, 52 int (*filter)(void *filter_ctx, struct lsquic_stream *), 53 void *filter_ctx); 54 55struct lsquic_stream * 56lsquic_hpi_first (void *); 57 58struct lsquic_stream * 59lsquic_hpi_next (void *); 60 61void 62lsquic_hpi_drop_non_high (void *); 63 64void 65lsquic_hpi_drop_high (void *); 66 67void 68lsquic_hpi_cleanup (void *); 69 70#ifndef NDEBUG 71#define LSQUIC_HPI_HEAP_TEST_STACK_OK (1 << 0) 72#define LSQUIC_HPI_HEAP_TEST_4K_OK (1 << 1) 73#if LSQUIC_TEST 74void 75lsquic_hpi_set_heap_test (int val); 76#endif 77#endif 78 79#endif 80