1 /* 2 * nghttp3 3 * 4 * Copyright (c) 2019 nghttp3 contributors 5 * Copyright (c) 2017 ngtcp2 contributors 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining 8 * a copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 #ifndef NGHTTP3_IDTR_H 27 #define NGHTTP3_IDTR_H 28 29 #ifdef HAVE_CONFIG_H 30 # include <config.h> 31 #endif /* HAVE_CONFIG_H */ 32 33 #include <nghttp3/nghttp3.h> 34 35 #include "nghttp3_mem.h" 36 #include "nghttp3_gaptr.h" 37 38 /* 39 * nghttp3_idtr tracks the usage of stream ID. 40 */ 41 typedef struct nghttp3_idtr { 42 /* gap maintains the range of ID which is not used yet. Initially, 43 its range is [0, UINT64_MAX). */ 44 nghttp3_gaptr gap; 45 /* server is nonzero if this object records server initiated stream 46 ID. */ 47 int server; 48 } nghttp3_idtr; 49 50 /* 51 * nghttp3_idtr_init initializes |idtr|. 52 * 53 * If this object records server initiated ID (even number), set 54 * |server| to nonzero. 55 */ 56 void nghttp3_idtr_init(nghttp3_idtr *idtr, int server, const nghttp3_mem *mem); 57 58 /* 59 * nghttp3_idtr_free frees resources allocated for |idtr|. 60 */ 61 void nghttp3_idtr_free(nghttp3_idtr *idtr); 62 63 /* 64 * nghttp3_idtr_open claims that |stream_id| is in used. 65 * 66 * It returns 0 if it succeeds, or one of the following negative error 67 * codes: 68 * 69 * NGHTTP3_ERR_STREAM_IN_USE 70 * ID has already been used. 71 * NGHTTP3_ERR_NOMEM 72 * Out of memory. 73 */ 74 int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id); 75 76 /* 77 * nghttp3_idtr_open tells whether ID |stream_id| is in used or not. 78 * 79 * It returns nonzero if |stream_id| is used. 80 */ 81 int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id); 82 83 /* 84 * nghttp3_idtr_first_gap returns the first id of first gap. If there 85 * is no gap, it returns UINT64_MAX. The returned id is an id space 86 * used in this object internally, and not stream ID. 87 */ 88 uint64_t nghttp3_idtr_first_gap(nghttp3_idtr *idtr); 89 90 #endif /* NGHTTP3_IDTR_H */ 91