openssl async job: clear the wait ctx when dropped

This commit is contained in:
Zhang Jingqiang 2023-12-26 18:56:05 +08:00
parent 84b6dc665d
commit f5b588966e

View file

@ -72,6 +72,26 @@ pub struct OpensslAsyncTask<T: AsyncOperation> {
action: Box<UnsafeCell<Action<T>>>,
}
impl<T: AsyncOperation> Drop for OpensslAsyncTask<T> {
fn drop(&mut self) {
if !self.job.is_null() {
let mut ret: c_int = 0;
// reset ctx in job to be null before we drop it
unsafe {
ffi::ASYNC_start_job(
&mut self.job,
ptr::null_mut(),
&mut ret,
None, // ignored
ptr::null_mut(), // ignored
0, // ignored
)
};
}
}
}
/// NOTE: OpensslAsyncTask in fact is not Send,
/// make sure you call it in a single threaded async runtime
unsafe impl<T: AsyncOperation + Send> Send for OpensslAsyncTask<T> {}
@ -241,6 +261,8 @@ where
type Output = Result<T::Output, OpensslAsyncTaskError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.get_mut().poll_run(cx)
let r = ready!(self.get_mut().poll_run(cx));
self.job = ptr::null_mut(); // reset
Poll::Ready(r)
}
}