Merge pull request #2353 from embassy-rs/smoltcp-011
Upgrade to smoltcp v0.11.
This commit is contained in:
commit
8b6c6c7df6
2 changed files with 18 additions and 9 deletions
|
@ -60,7 +60,7 @@ igmp = ["smoltcp/proto-igmp"]
|
||||||
defmt = { version = "0.3", optional = true }
|
defmt = { version = "0.3", optional = true }
|
||||||
log = { version = "0.4.14", optional = true }
|
log = { version = "0.4.14", optional = true }
|
||||||
|
|
||||||
smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp.git", rev = "b57e2f9e70e82a13f31d5ea17e55232c11cc2b2d", default-features = false, features = [
|
smoltcp = { version = "0.11.0", default-features = false, features = [
|
||||||
"socket",
|
"socket",
|
||||||
"async",
|
"async",
|
||||||
] }
|
] }
|
||||||
|
|
|
@ -26,13 +26,21 @@ pub enum BindError {
|
||||||
/// Error returned by [`UdpSocket::recv_from`] and [`UdpSocket::send_to`].
|
/// Error returned by [`UdpSocket::recv_from`] and [`UdpSocket::send_to`].
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
pub enum Error {
|
pub enum SendError {
|
||||||
/// No route to host.
|
/// No route to host.
|
||||||
NoRoute,
|
NoRoute,
|
||||||
/// Socket not bound to an outgoing port.
|
/// Socket not bound to an outgoing port.
|
||||||
SocketNotBound,
|
SocketNotBound,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Error returned by [`UdpSocket::recv_from`] and [`UdpSocket::send_to`].
|
||||||
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
|
pub enum RecvError {
|
||||||
|
/// Provided buffer was smaller than the received packet.
|
||||||
|
Truncated,
|
||||||
|
}
|
||||||
|
|
||||||
/// An UDP socket.
|
/// An UDP socket.
|
||||||
pub struct UdpSocket<'a> {
|
pub struct UdpSocket<'a> {
|
||||||
stack: &'a RefCell<SocketStack>,
|
stack: &'a RefCell<SocketStack>,
|
||||||
|
@ -103,7 +111,7 @@ impl<'a> UdpSocket<'a> {
|
||||||
/// This method will wait until a datagram is received.
|
/// This method will wait until a datagram is received.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes received and the remote endpoint.
|
/// Returns the number of bytes received and the remote endpoint.
|
||||||
pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), Error> {
|
pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), RecvError> {
|
||||||
poll_fn(move |cx| self.poll_recv_from(buf, cx)).await
|
poll_fn(move |cx| self.poll_recv_from(buf, cx)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,10 +122,11 @@ impl<'a> UdpSocket<'a> {
|
||||||
///
|
///
|
||||||
/// When a datagram is received, this method will return `Poll::Ready` with the
|
/// When a datagram is received, this method will return `Poll::Ready` with the
|
||||||
/// number of bytes received and the remote endpoint.
|
/// number of bytes received and the remote endpoint.
|
||||||
pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll<Result<(usize, IpEndpoint), Error>> {
|
pub fn poll_recv_from(&self, buf: &mut [u8], cx: &mut Context<'_>) -> Poll<Result<(usize, IpEndpoint), RecvError>> {
|
||||||
self.with_mut(|s, _| match s.recv_slice(buf) {
|
self.with_mut(|s, _| match s.recv_slice(buf) {
|
||||||
Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))),
|
Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))),
|
||||||
// No data ready
|
// No data ready
|
||||||
|
Err(udp::RecvError::Truncated) => Poll::Ready(Err(RecvError::Truncated)),
|
||||||
Err(udp::RecvError::Exhausted) => {
|
Err(udp::RecvError::Exhausted) => {
|
||||||
s.register_recv_waker(cx.waker());
|
s.register_recv_waker(cx.waker());
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
|
@ -129,8 +138,8 @@ impl<'a> UdpSocket<'a> {
|
||||||
///
|
///
|
||||||
/// This method will wait until the datagram has been sent.
|
/// This method will wait until the datagram has been sent.
|
||||||
///
|
///
|
||||||
/// When the remote endpoint is not reachable, this method will return `Err(Error::NoRoute)`
|
/// When the remote endpoint is not reachable, this method will return `Err(SendError::NoRoute)`
|
||||||
pub async fn send_to<T>(&self, buf: &[u8], remote_endpoint: T) -> Result<(), Error>
|
pub async fn send_to<T>(&self, buf: &[u8], remote_endpoint: T) -> Result<(), SendError>
|
||||||
where
|
where
|
||||||
T: Into<IpEndpoint>,
|
T: Into<IpEndpoint>,
|
||||||
{
|
{
|
||||||
|
@ -146,7 +155,7 @@ impl<'a> UdpSocket<'a> {
|
||||||
/// and register the current task to be notified when the buffer has space available.
|
/// and register the current task to be notified when the buffer has space available.
|
||||||
///
|
///
|
||||||
/// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`.
|
/// When the remote endpoint is not reachable, this method will return `Poll::Ready(Err(Error::NoRoute))`.
|
||||||
pub fn poll_send_to<T>(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
|
pub fn poll_send_to<T>(&self, buf: &[u8], remote_endpoint: T, cx: &mut Context<'_>) -> Poll<Result<(), SendError>>
|
||||||
where
|
where
|
||||||
T: Into<IpEndpoint>,
|
T: Into<IpEndpoint>,
|
||||||
{
|
{
|
||||||
|
@ -160,9 +169,9 @@ impl<'a> UdpSocket<'a> {
|
||||||
Err(udp::SendError::Unaddressable) => {
|
Err(udp::SendError::Unaddressable) => {
|
||||||
// If no sender/outgoing port is specified, there is not really "no route"
|
// If no sender/outgoing port is specified, there is not really "no route"
|
||||||
if s.endpoint().port == 0 {
|
if s.endpoint().port == 0 {
|
||||||
Poll::Ready(Err(Error::SocketNotBound))
|
Poll::Ready(Err(SendError::SocketNotBound))
|
||||||
} else {
|
} else {
|
||||||
Poll::Ready(Err(Error::NoRoute))
|
Poll::Ready(Err(SendError::NoRoute))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue