2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
use super :: Credits ;
5
- use crate :: stream:: send:: {
6
- error:: { self , Error } ,
7
- flow,
5
+ use crate :: stream:: {
6
+ send:: {
7
+ error:: { self , Error } ,
8
+ flow,
9
+ } ,
10
+ TransportFeatures ,
8
11
} ;
9
12
use atomic_waker:: AtomicWaker ;
10
13
use core:: {
@@ -96,8 +99,12 @@ impl State {
96
99
97
100
/// Called by the application to acquire flow credits
98
101
#[ inline]
99
- pub async fn acquire ( & self , request : flow:: Request ) -> Result < Credits , Error > {
100
- core:: future:: poll_fn ( |cx| self . poll_acquire ( cx, request) ) . await
102
+ pub async fn acquire (
103
+ & self ,
104
+ request : flow:: Request ,
105
+ features : & TransportFeatures ,
106
+ ) -> Result < Credits , Error > {
107
+ core:: future:: poll_fn ( |cx| self . poll_acquire ( cx, request, features) ) . await
101
108
}
102
109
103
110
/// Called by the application to acquire flow credits
@@ -106,6 +113,7 @@ impl State {
106
113
& self ,
107
114
cx : & mut Context ,
108
115
mut request : flow:: Request ,
116
+ features : & TransportFeatures ,
109
117
) -> Poll < Result < Credits , Error > > {
110
118
let mut current_offset = self . acquire_offset ( & request) ?;
111
119
@@ -138,8 +146,10 @@ impl State {
138
146
continue ;
139
147
} ;
140
148
141
- // clamp the request to the flow credits we have
142
- request. clamp ( flow_credits) ;
149
+ if !features. is_flow_controlled ( ) {
150
+ // clamp the request to the flow credits we have
151
+ request. clamp ( flow_credits) ;
152
+ }
143
153
144
154
let mut new_offset = ( current_offset & OFFSET_MASK )
145
155
. checked_add ( request. len as u64 )
@@ -223,6 +233,7 @@ mod tests {
223
233
// TODO support more than one Waker via intrusive list or something
224
234
let workers = 1 ;
225
235
let worker_counts = Vec :: from_iter ( ( 0 ..workers) . map ( |_| Arc :: new ( AtomicU64 :: new ( 0 ) ) ) ) ;
236
+ let features = TransportFeatures :: UDP ;
226
237
227
238
let mut tasks = tokio:: task:: JoinSet :: new ( ) ;
228
239
@@ -246,7 +257,7 @@ mod tests {
246
257
} ;
247
258
request. clamp ( path_info. max_flow_credits ( max_header_len, max_segments) ) ;
248
259
249
- let Ok ( credits) = state. acquire ( request) . await else {
260
+ let Ok ( credits) = state. acquire ( request, & features ) . await else {
250
261
break ;
251
262
} ;
252
263
0 commit comments