Handle cancellation
This commit is contained in:
parent
9cfea693ed
commit
c203cefe01
@ -40,6 +40,7 @@ smoltcp = { version = "0.9.0", default-features = false, features = [
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
|
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
|
||||||
|
embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common" }
|
||||||
embassy-time = { version = "0.1.0", path = "../embassy-time" }
|
embassy-time = { version = "0.1.0", path = "../embassy-time" }
|
||||||
embassy-sync = { version = "0.1.0", path = "../embassy-sync" }
|
embassy-sync = { version = "0.1.0", path = "../embassy-sync" }
|
||||||
embedded-io = { version = "0.4.0", optional = true }
|
embedded-io = { version = "0.4.0", optional = true }
|
||||||
|
@ -11,6 +11,7 @@ use smoltcp::iface::{Interface, SocketHandle};
|
|||||||
pub use smoltcp::socket::dns::DnsQuery;
|
pub use smoltcp::socket::dns::DnsQuery;
|
||||||
use smoltcp::socket::dns::{self, GetQueryResultError, StartQueryError, MAX_ADDRESS_COUNT};
|
use smoltcp::socket::dns::{self, GetQueryResultError, StartQueryError, MAX_ADDRESS_COUNT};
|
||||||
pub use smoltcp::wire::{DnsQueryType, IpAddress};
|
pub use smoltcp::wire::{DnsQueryType, IpAddress};
|
||||||
|
use embassy_hal_common::drop::OnDrop;
|
||||||
|
|
||||||
use crate::{SocketStack, Stack};
|
use crate::{SocketStack, Stack};
|
||||||
|
|
||||||
@ -93,7 +94,15 @@ impl<'a> DnsSocket<'a> {
|
|||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
poll_fn(|cx| {
|
let handle = self.handle;
|
||||||
|
let drop = OnDrop::new(|| {
|
||||||
|
let s = &mut *self.stack.borrow_mut();
|
||||||
|
let socket = s.sockets.get_mut::<dns::Socket>(handle);
|
||||||
|
socket.cancel_query(query);
|
||||||
|
s.waker.wake();
|
||||||
|
});
|
||||||
|
|
||||||
|
let res = poll_fn(|cx| {
|
||||||
self.with_mut(|s, _| match s.get_query_result(query) {
|
self.with_mut(|s, _| match s.get_query_result(query) {
|
||||||
Ok(addrs) => Poll::Ready(Ok(addrs)),
|
Ok(addrs) => Poll::Ready(Ok(addrs)),
|
||||||
Err(GetQueryResultError::Pending) => {
|
Err(GetQueryResultError::Pending) => {
|
||||||
@ -103,7 +112,10 @@ impl<'a> DnsSocket<'a> {
|
|||||||
Err(e) => Poll::Ready(Err(e.into())),
|
Err(e) => Poll::Ready(Err(e.into())),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await;
|
||||||
|
|
||||||
|
drop.defuse();
|
||||||
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user