1 /*
2  * Copyright (c) 2017 Fastly, Kazuho Oku
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 #ifndef quicly_sendstate_h
23 #define quicly_sendstate_h
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include "quicly/ranges.h"
30 
31 typedef struct st_quicly_sendstate_t {
32     /**
33      * ranges that have been acked (guaranteed to be non-empty; i.e., acked.ranges[0].end == contiguous_acked_offset).  Offset may
34      * include the EOS position.
35      */
36     quicly_ranges_t acked;
37     /**
38      * ranges that needs to be sent.  Offset may include the EOS position.
39      */
40     quicly_ranges_t pending;
41     /**
42      * number of bytes that have been inflight (regardless of acked or not). Used for capping max_data, therefore does not include
43      * eos.
44      */
45     uint64_t size_inflight;
46     /**
47      * UINT64_MAX until closed.  Does not include the EOS position.
48      */
49     uint64_t final_size;
50 } quicly_sendstate_t;
51 
52 typedef struct st_quicly_sendstate_sent_t {
53     uint64_t start;
54     uint64_t end;
55 } quicly_sendstate_sent_t;
56 
57 void quicly_sendstate_init(quicly_sendstate_t *state);
58 void quicly_sendstate_init_closed(quicly_sendstate_t *state);
59 void quicly_sendstate_dispose(quicly_sendstate_t *state);
60 static int quicly_sendstate_transfer_complete(quicly_sendstate_t *state);
61 static int quicly_sendstate_is_open(quicly_sendstate_t *state);
62 int quicly_sendstate_activate(quicly_sendstate_t *state);
63 int quicly_sendstate_shutdown(quicly_sendstate_t *state, uint64_t final_size);
64 void quicly_sendstate_reset(quicly_sendstate_t *state);
65 int quicly_sendstate_acked(quicly_sendstate_t *state, quicly_sendstate_sent_t *args, size_t *bytes_to_shift);
66 int quicly_sendstate_lost(quicly_sendstate_t *state, quicly_sendstate_sent_t *args);
67 
68 /* inline definitions */
69 
quicly_sendstate_transfer_complete(quicly_sendstate_t * state)70 inline int quicly_sendstate_transfer_complete(quicly_sendstate_t *state)
71 {
72     return state->final_size != UINT64_MAX && state->acked.ranges[0].end == state->final_size + 1;
73 }
74 
quicly_sendstate_is_open(quicly_sendstate_t * state)75 inline int quicly_sendstate_is_open(quicly_sendstate_t *state)
76 {
77     return state->final_size == UINT64_MAX;
78 }
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
85