summaryrefslogtreecommitdiff
path: root/embassy-net/src
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net/src')
-rw-r--r--embassy-net/src/lib.rs3
-rw-r--r--embassy-net/src/tcp.rs120
2 files changed, 75 insertions, 48 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 83d36471..8eebc798 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -1,6 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
-#![allow(clippy::new_without_default)]
-#![feature(generic_associated_types, type_alias_impl_trait)]
+#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))]
// This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt;
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index 910772c7..0fa87360 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -1,5 +1,4 @@
use core::cell::UnsafeCell;
-use core::future::Future;
use core::mem;
use core::task::Poll;
@@ -55,6 +54,18 @@ pub struct TcpWriter<'a> {
io: TcpIo<'a>,
}
+impl<'a> TcpReader<'a> {
+ pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
+ self.io.read(buf).await
+ }
+}
+
+impl<'a> TcpWriter<'a> {
+ pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error> {
+ self.io.write(buf).await
+ }
+}
+
impl<'a> TcpSocket<'a> {
pub fn new<D: Device>(stack: &'a Stack<D>, rx_buffer: &'a mut [u8], tx_buffer: &'a mut [u8]) -> Self {
// safety: not accessed reentrantly.
@@ -129,6 +140,14 @@ impl<'a> TcpSocket<'a> {
.await
}
+ pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
+ self.io.read(buf).await
+ }
+
+ pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error> {
+ self.io.write(buf).await
+ }
+
pub fn set_timeout(&mut self, duration: Option<Duration>) {
unsafe { self.io.with_mut(|s, _| s.set_timeout(duration)) }
}
@@ -241,6 +260,7 @@ impl<'d> TcpIo<'d> {
.await
}
+ #[allow(unused)]
async fn flush(&mut self) -> Result<(), Error> {
poll_fn(move |_| {
Poll::Ready(Ok(())) // TODO: Is there a better implementation for this?
@@ -249,88 +269,96 @@ impl<'d> TcpIo<'d> {
}
}
-impl embedded_io::Error for ConnectError {
- fn kind(&self) -> embedded_io::ErrorKind {
- embedded_io::ErrorKind::Other
+#[cfg(feature = "nightly")]
+mod embedded_io_impls {
+ use core::future::Future;
+
+ use super::*;
+
+ impl embedded_io::Error for ConnectError {
+ fn kind(&self) -> embedded_io::ErrorKind {
+ embedded_io::ErrorKind::Other
+ }
}
-}
-impl embedded_io::Error for Error {
- fn kind(&self) -> embedded_io::ErrorKind {
- embedded_io::ErrorKind::Other
+ impl embedded_io::Error for Error {
+ fn kind(&self) -> embedded_io::ErrorKind {
+ embedded_io::ErrorKind::Other
+ }
}
-}
-impl<'d> embedded_io::Io for TcpSocket<'d> {
- type Error = Error;
-}
+ impl<'d> embedded_io::Io for TcpSocket<'d> {
+ type Error = Error;
+ }
-impl<'d> embedded_io::asynch::Read for TcpSocket<'d> {
- type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
+ impl<'d> embedded_io::asynch::Read for TcpSocket<'d> {
+ type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
where
Self: 'a;
- fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
- self.io.read(buf)
+ fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
+ self.io.read(buf)
+ }
}
-}
-impl<'d> embedded_io::asynch::Write for TcpSocket<'d> {
- type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
+ impl<'d> embedded_io::asynch::Write for TcpSocket<'d> {
+ type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
where
Self: 'a;
- fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
- self.io.write(buf)
- }
+ fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
+ self.io.write(buf)
+ }
- type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
+ type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
where
Self: 'a;
- fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
- self.io.flush()
+ fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
+ self.io.flush()
+ }
}
-}
-impl<'d> embedded_io::Io for TcpReader<'d> {
- type Error = Error;
-}
+ impl<'d> embedded_io::Io for TcpReader<'d> {
+ type Error = Error;
+ }
-impl<'d> embedded_io::asynch::Read for TcpReader<'d> {
- type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
+ impl<'d> embedded_io::asynch::Read for TcpReader<'d> {
+ type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
where
Self: 'a;
- fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
- self.io.read(buf)
+ fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
+ self.io.read(buf)
+ }
}
-}
-impl<'d> embedded_io::Io for TcpWriter<'d> {
- type Error = Error;
-}
+ impl<'d> embedded_io::Io for TcpWriter<'d> {
+ type Error = Error;
+ }
-impl<'d> embedded_io::asynch::Write for TcpWriter<'d> {
- type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
+ impl<'d> embedded_io::asynch::Write for TcpWriter<'d> {
+ type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>>
where
Self: 'a;
- fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
- self.io.write(buf)
- }
+ fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
+ self.io.write(buf)
+ }
- type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
+ type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
where
Self: 'a;
- fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
- self.io.flush()
+ fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
+ self.io.flush()
+ }
}
}
-#[cfg(feature = "unstable-traits")]
+#[cfg(all(feature = "unstable-traits", feature = "nightly"))]
pub mod client {
+ use core::future::Future;
use core::mem::MaybeUninit;
use core::ptr::NonNull;