@@ -174,6 +174,7 @@ where
174
174
buf : [ MaybeUninit :: uninit ( ) ; 24 ] ,
175
175
filled : 0 ,
176
176
version : Version :: H2 ,
177
+ cancelled : false ,
177
178
_pin : PhantomPinned ,
178
179
}
179
180
}
@@ -185,12 +186,19 @@ pin_project! {
185
186
// the amount of `buf` thats been filled
186
187
filled: usize ,
187
188
version: Version ,
189
+ cancelled: bool ,
188
190
// Make this future `!Unpin` for compatibility with async trait methods.
189
191
#[ pin]
190
192
_pin: PhantomPinned ,
191
193
}
192
194
}
193
195
196
+ impl < I > ReadVersion < I > {
197
+ pub fn cancel ( self : Pin < & mut Self > ) {
198
+ * self . project ( ) . cancelled = true ;
199
+ }
200
+ }
201
+
194
202
impl < I > Future for ReadVersion < I >
195
203
where
196
204
I : Read + Unpin ,
@@ -199,6 +207,9 @@ where
199
207
200
208
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
201
209
let this = self . project ( ) ;
210
+ if * this. cancelled {
211
+ return Poll :: Ready ( Err ( io:: Error :: new ( io:: ErrorKind :: Interrupted , "Cancelled" ) ) ) ;
212
+ }
202
213
203
214
let mut buf = ReadBuf :: uninit ( & mut * this. buf ) ;
204
215
// SAFETY: `this.filled` tracks how many bytes have been read (and thus initialized) and
@@ -296,7 +307,7 @@ where
296
307
/// `Connection::poll` has resolved, this does nothing.
297
308
pub fn graceful_shutdown ( self : Pin < & mut Self > ) {
298
309
match self . project ( ) . state . project ( ) {
299
- ConnStateProj :: ReadVersion { .. } => { }
310
+ ConnStateProj :: ReadVersion { read_version , .. } => read_version . cancel ( ) ,
300
311
#[ cfg( feature = "http1" ) ]
301
312
ConnStateProj :: H1 { conn } => conn. graceful_shutdown ( ) ,
302
313
#[ cfg( feature = "http2" ) ]
@@ -420,7 +431,7 @@ where
420
431
/// called after `UpgradeableConnection::poll` has resolved, this does nothing.
421
432
pub fn graceful_shutdown ( self : Pin < & mut Self > ) {
422
433
match self . project ( ) . state . project ( ) {
423
- UpgradeableConnStateProj :: ReadVersion { .. } => { }
434
+ UpgradeableConnStateProj :: ReadVersion { read_version , .. } => read_version . cancel ( ) ,
424
435
#[ cfg( feature = "http1" ) ]
425
436
UpgradeableConnStateProj :: H1 { conn } => conn. graceful_shutdown ( ) ,
426
437
#[ cfg( feature = "http2" ) ]
0 commit comments