mirror of
https://github.com/bytedance/g3.git
synced 2026-05-19 16:28:21 +00:00
openssl async job: clear the wait ctx when dropped
This commit is contained in:
parent
84b6dc665d
commit
f5b588966e
1 changed files with 23 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue