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