aboutsummaryrefslogtreecommitdiff
path: root/embassy-net/src
diff options
context:
space:
mode:
authorGustav Toft <[email protected]>2024-04-10 09:07:20 +0200
committerGustav Toft <[email protected]>2024-04-10 09:07:20 +0200
commit6663be0b36a078893b0ef3f3f869b17adf62ca30 (patch)
treee6d34af1e56d4753bcfcd5cd154d8d3ac821dab4 /embassy-net/src
parenta373633d0dbc352de1b488bf15e383f8ef1d4a8c (diff)
Fixed commented issues.
Diffstat (limited to 'embassy-net/src')
-rw-r--r--embassy-net/src/lib.rs4
-rw-r--r--embassy-net/src/raw.rs64
2 files changed, 5 insertions, 63 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 05c8aec7b..86ced1ded 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -15,13 +15,13 @@ pub(crate) mod fmt;
15mod device; 15mod device;
16#[cfg(feature = "dns")] 16#[cfg(feature = "dns")]
17pub mod dns; 17pub mod dns;
18#[cfg(feature = "raw")]
19pub mod raw;
18#[cfg(feature = "tcp")] 20#[cfg(feature = "tcp")]
19pub mod tcp; 21pub mod tcp;
20mod time; 22mod time;
21#[cfg(feature = "udp")] 23#[cfg(feature = "udp")]
22pub mod udp; 24pub mod udp;
23#[cfg(feature = "raw")]
24pub mod raw;
25 25
26use core::cell::RefCell; 26use core::cell::RefCell;
27use core::future::{poll_fn, Future}; 27use core::future::{poll_fn, Future};
diff --git a/embassy-net/src/raw.rs b/embassy-net/src/raw.rs
index a0e458fff..ad8d69853 100644
--- a/embassy-net/src/raw.rs
+++ b/embassy-net/src/raw.rs
@@ -13,28 +13,6 @@ use smoltcp::wire::{IpProtocol, IpVersion};
13 13
14use crate::{SocketStack, Stack}; 14use crate::{SocketStack, Stack};
15 15
16
17/// Unrelavent for RawSocket?
18/* /// Error returned by [`RawSocket::bind`].
19#[derive(PartialEq, Eq, Clone, Copy, Debug)]
20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
21pub enum BindError {
22 /// The socket was already open.
23 InvalidState,
24 /// No route to host.
25 NoRoute,
26} */
27
28/// Error returned by [`RawSocket::recv_from`] and [`RawSocket::send_to`].
29#[derive(PartialEq, Eq, Clone, Copy, Debug)]
30#[cfg_attr(feature = "defmt", derive(defmt::Format))]
31pub enum SendError {
32 /// No route to host.
33 NoRoute,
34 /// Socket not bound to an outgoing port.
35 SocketNotBound,
36}
37
38/// Error returned by [`RawSocket::recv`] and [`RawSocket::send`]. 16/// Error returned by [`RawSocket::recv`] and [`RawSocket::send`].
39#[derive(PartialEq, Eq, Clone, Copy, Debug)] 17#[derive(PartialEq, Eq, Clone, Copy, Debug)]
40#[cfg_attr(feature = "defmt", derive(defmt::Format))] 18#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -87,42 +65,6 @@ impl<'a> RawSocket<'a> {
87 res 65 res
88 } 66 }
89 67
90 /// Bind the socket to a local endpoint.
91 ///
92 /// How to handle this in RawSocket? no need for bind?
93 ///
94 /* pub fn bind<T>(&mut self, endpoint: T) -> Result<(), BindError>
95 where
96 T: Into<IpListenEndpoint>,
97 {
98 let mut endpoint = endpoint.into();
99
100 if endpoint.port == 0 {
101 // If user didn't specify port allocate a dynamic port.
102 endpoint.port = self.stack.borrow_mut().get_local_port();
103 }
104
105 match self.with_mut(|s, _| s.bind(endpoint)) {
106 Ok(()) => Ok(()),
107 Err(raw::BindError::InvalidState) => Err(BindError::InvalidState),
108 Err(raw::BindError::Unaddressable) => Err(BindError::NoRoute),
109 }
110 }
111
112 fn with<R>(&self, f: impl FnOnce(&raw::Socket, &Interface) -> R) -> R {
113 let s = &*self.stack.borrow();
114 let socket = s.sockets.get::<raw::Socket>(self.handle);
115 f(socket, &s.iface)
116 }
117
118 fn with_mut<R>(&self, f: impl FnOnce(&mut raw::Socket, &mut Interface) -> R) -> R {
119 let s = &mut *self.stack.borrow_mut();
120 let socket = s.sockets.get_mut::<raw::Socket>(self.handle);
121 let res = f(socket, &mut s.iface);
122 s.waker.wake();
123 res
124 } */
125
126 /// Receive a datagram. 68 /// Receive a datagram.
127 /// 69 ///
128 /// This method will wait until a datagram is received. 70 /// This method will wait until a datagram is received.
@@ -149,7 +91,7 @@ impl<'a> RawSocket<'a> {
149 /// Send a datagram. 91 /// Send a datagram.
150 /// 92 ///
151 /// This method will wait until the datagram has been sent.` 93 /// This method will wait until the datagram has been sent.`
152 pub async fn send<T>(&self, buf: &[u8]) -> Result<(), SendError> { 94 pub async fn send<T>(&self, buf: &[u8]) -> Result<(), raw::SendError> {
153 poll_fn(move |cx| self.poll_send(buf, cx)).await 95 poll_fn(move |cx| self.poll_send(buf, cx)).await
154 } 96 }
155 97
@@ -159,7 +101,7 @@ impl<'a> RawSocket<'a> {
159 /// 101 ///
160 /// When the socket's send buffer is full, this method will return `Poll::Pending` 102 /// When the socket's send buffer is full, this method will return `Poll::Pending`
161 /// and register the current task to be notified when the buffer has space available. 103 /// and register the current task to be notified when the buffer has space available.
162 pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll<Result<(), SendError>>{ 104 pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll<Result<(), raw::SendError>> {
163 self.with_mut(|s, _| match s.send_slice(buf) { 105 self.with_mut(|s, _| match s.send_slice(buf) {
164 // Entire datagram has been sent 106 // Entire datagram has been sent
165 Ok(()) => Poll::Ready(Ok(())), 107 Ok(()) => Poll::Ready(Ok(())),
@@ -169,7 +111,7 @@ impl<'a> RawSocket<'a> {
169 } 111 }
170 }) 112 })
171 } 113 }
172 } 114}
173 115
174impl Drop for RawSocket<'_> { 116impl Drop for RawSocket<'_> {
175 fn drop(&mut self) { 117 fn drop(&mut self) {