@@ -26,10 +26,10 @@ pub type ExDataFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
26
26
27
27
pub ( crate ) static TASK_WAKER_INDEX : Lazy < Index < Ssl , Option < Waker > > > =
28
28
Lazy :: new ( || Ssl :: new_ex_index ( ) . unwrap ( ) ) ;
29
- pub ( crate ) static SELECT_CERT_FUTURE_INDEX : Lazy < Index < Ssl , BoxSelectCertFuture > > =
29
+ pub ( crate ) static SELECT_CERT_FUTURE_INDEX : Lazy < Index < Ssl , Option < BoxSelectCertFuture > > > =
30
30
Lazy :: new ( || Ssl :: new_ex_index ( ) . unwrap ( ) ) ;
31
31
pub ( crate ) static SELECT_PRIVATE_KEY_METHOD_FUTURE_INDEX : Lazy <
32
- Index < Ssl , BoxPrivateKeyMethodFuture > ,
32
+ Index < Ssl , Option < BoxPrivateKeyMethodFuture > > ,
33
33
> = Lazy :: new ( || Ssl :: new_ex_index ( ) . unwrap ( ) ) ;
34
34
35
35
/// Extensions to [`SslContextBuilder`].
@@ -219,7 +219,7 @@ fn with_private_key_method(
219
219
/// created by `create_fut` returns `Poll::Ready(_)` on the first poll call.
220
220
fn with_ex_data_future < H , T , E > (
221
221
ssl_handle : & mut H ,
222
- index : Index < ssl:: Ssl , ExDataFuture < Result < T , E > > > ,
222
+ index : Index < ssl:: Ssl , Option < ExDataFuture < Result < T , E > > > > ,
223
223
get_ssl_mut : impl Fn ( & mut H ) -> & mut ssl:: SslRef ,
224
224
create_fut : impl FnOnce ( & mut H ) -> Result < ExDataFuture < Result < T , E > > , E > ,
225
225
) -> Poll < Result < T , E > > {
@@ -232,25 +232,21 @@ fn with_ex_data_future<H, T, E>(
232
232
233
233
let mut ctx = Context :: from_waker ( & waker) ;
234
234
235
- match ssl. ex_data_mut ( index) {
236
- Some ( fut) => {
237
- let fut_result = ready ! ( fut. as_mut( ) . poll( & mut ctx) ) ;
235
+ if let Some ( data @ Some ( _) ) = ssl. ex_data_mut ( index) {
236
+ let fut_result = ready ! ( data. as_mut( ) . unwrap( ) . as_mut( ) . poll( & mut ctx) ) ;
238
237
239
- // NOTE(nox): For memory usage concerns, maybe we should implement
240
- // a way to remove the stored future from the `Ssl` value here?
238
+ * data = None ;
241
239
242
- Poll :: Ready ( fut_result)
243
- }
244
- None => {
245
- let mut fut = create_fut ( ssl_handle) ?;
240
+ Poll :: Ready ( fut_result)
241
+ } else {
242
+ let mut fut = create_fut ( ssl_handle) ?;
246
243
247
- match fut. as_mut ( ) . poll ( & mut ctx) {
248
- Poll :: Ready ( fut_result) => Poll :: Ready ( fut_result) ,
249
- Poll :: Pending => {
250
- get_ssl_mut ( ssl_handle) . set_ex_data ( index, fut) ;
244
+ match fut. as_mut ( ) . poll ( & mut ctx) {
245
+ Poll :: Ready ( fut_result) => Poll :: Ready ( fut_result) ,
246
+ Poll :: Pending => {
247
+ get_ssl_mut ( ssl_handle) . set_ex_data ( index, Some ( fut) ) ;
251
248
252
- Poll :: Pending
253
- }
249
+ Poll :: Pending
254
250
}
255
251
}
256
252
}
0 commit comments