Removed UB code around the send future
This commit is contained in:
parent
baab52d40c
commit
7c723d2bfd
@ -210,7 +210,7 @@ where
|
|||||||
pub async fn send(&self, message: T) -> Result<(), SendError<T>> {
|
pub async fn send(&self, message: T) -> Result<(), SendError<T>> {
|
||||||
SendFuture {
|
SendFuture {
|
||||||
sender: self.clone(),
|
sender: self.clone(),
|
||||||
message: UnsafeCell::new(message),
|
message: Some(message),
|
||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ where
|
|||||||
M: Mutex<Data = ()>,
|
M: Mutex<Data = ()>,
|
||||||
{
|
{
|
||||||
sender: Sender<'ch, M, T, N>,
|
sender: Sender<'ch, M, T, N>,
|
||||||
message: UnsafeCell<T>,
|
message: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ch, M, T, const N: usize> Future for SendFuture<'ch, M, T, N>
|
impl<'ch, M, T, const N: usize> Future for SendFuture<'ch, M, T, N>
|
||||||
@ -275,25 +275,23 @@ where
|
|||||||
{
|
{
|
||||||
type Output = Result<(), SendError<T>>;
|
type Output = Result<(), SendError<T>>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
match self
|
match self.message.take() {
|
||||||
.sender
|
Some(m) => match self.sender.channel.get().try_send_with_context(m, Some(cx)) {
|
||||||
.channel
|
|
||||||
.get()
|
|
||||||
.try_send_with_context(unsafe { self.message.get().read() }, Some(cx))
|
|
||||||
{
|
|
||||||
Ok(..) => Poll::Ready(Ok(())),
|
Ok(..) => Poll::Ready(Ok(())),
|
||||||
Err(TrySendError::Closed(m)) => Poll::Ready(Err(SendError(m))),
|
Err(TrySendError::Closed(m)) => Poll::Ready(Err(SendError(m))),
|
||||||
Err(TrySendError::Full(..)) => {
|
Err(TrySendError::Full(m)) => {
|
||||||
|
self.message.insert(m);
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
// Note we leave the existing UnsafeCell contents - they still
|
}
|
||||||
// contain the original message. We could create another UnsafeCell
|
},
|
||||||
// with the message of Full, but there's no real need.
|
None => panic!("Message cannot be None"),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'ch, M, T, const N: usize> Unpin for SendFuture<'ch, M, T, N> where M: Mutex<Data = ()> {}
|
||||||
|
|
||||||
struct CloseFuture<'ch, M, T, const N: usize>
|
struct CloseFuture<'ch, M, T, const N: usize>
|
||||||
where
|
where
|
||||||
M: Mutex<Data = ()>,
|
M: Mutex<Data = ()>,
|
||||||
|
Loading…
Reference in New Issue
Block a user