@@ -26,10 +26,10 @@ pub type ExDataFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
2626
2727pub ( crate ) static TASK_WAKER_INDEX : Lazy < Index < Ssl , Option < Waker > > > =
2828 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 > > > =
3030 Lazy :: new ( || Ssl :: new_ex_index ( ) . unwrap ( ) ) ;
3131pub ( crate ) static SELECT_PRIVATE_KEY_METHOD_FUTURE_INDEX : Lazy <
32- Index < Ssl , BoxPrivateKeyMethodFuture > ,
32+ Index < Ssl , Option < BoxPrivateKeyMethodFuture > > ,
3333> = Lazy :: new ( || Ssl :: new_ex_index ( ) . unwrap ( ) ) ;
3434
3535/// Extensions to [`SslContextBuilder`].
@@ -219,7 +219,7 @@ fn with_private_key_method(
219219/// created by `create_fut` returns `Poll::Ready(_)` on the first poll call.
220220fn with_ex_data_future < H , T , E > (
221221 ssl_handle : & mut H ,
222- index : Index < ssl:: Ssl , ExDataFuture < Result < T , E > > > ,
222+ index : Index < ssl:: Ssl , Option < ExDataFuture < Result < T , E > > > > ,
223223 get_ssl_mut : impl Fn ( & mut H ) -> & mut ssl:: SslRef ,
224224 create_fut : impl FnOnce ( & mut H ) -> Result < ExDataFuture < Result < T , E > > , E > ,
225225) -> Poll < Result < T , E > > {
@@ -232,25 +232,21 @@ fn with_ex_data_future<H, T, E>(
232232
233233 let mut ctx = Context :: from_waker ( & waker) ;
234234
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) ) ;
238237
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 ;
241239
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) ?;
246243
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) ) ;
251248
252- Poll :: Pending
253- }
249+ Poll :: Pending
254250 }
255251 }
256252 }
0 commit comments