Renaming trait function names, cleaning up docs
This commit is contained in:
parent
516bdae999
commit
0d47ea0982
3 changed files with 107 additions and 82 deletions
41
src/tcp.rs
41
src/tcp.rs
|
|
@ -65,13 +65,13 @@ impl TcpSocket {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn close<B: Bus>(&self, bus: &mut B) -> Result<(), TcpSocketError<B::Error>> {
|
||||
fn _close<B: Bus>(&self, bus: &mut B) -> Result<(), TcpSocketError<B::Error>> {
|
||||
self.socket.set_mode(bus, socketn::Protocol::Closed)?;
|
||||
self.socket.command(bus, socketn::Command::Close)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn connect<B: Bus>(
|
||||
fn _connect<B: Bus>(
|
||||
&mut self,
|
||||
bus: &mut B,
|
||||
remote: SocketAddrV4,
|
||||
|
|
@ -89,7 +89,7 @@ impl TcpSocket {
|
|||
// All other cases are transient TCP states. For these, we need to reset the TCP
|
||||
// machinery to return to the INIT state.
|
||||
Ok(_) => {
|
||||
self.close(bus)?;
|
||||
self._close(bus)?;
|
||||
self.reopen(bus)?;
|
||||
}
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ impl TcpSocket {
|
|||
Ok(socketn::Status::Closed) => {
|
||||
// For now, always return an open socket so that the user can re-connect with
|
||||
// it in the future.
|
||||
self.close(bus)?;
|
||||
self._close(bus)?;
|
||||
return self.reopen(bus);
|
||||
}
|
||||
|
||||
|
|
@ -126,16 +126,16 @@ impl TcpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_connected<B: Bus>(&self, bus: &mut B) -> Result<bool, TcpSocketError<B::Error>> {
|
||||
fn _is_connected<B: Bus>(&self, bus: &mut B) -> Result<bool, TcpSocketError<B::Error>> {
|
||||
Ok(self.socket.get_status(bus)? == socketn::Status::Established as u8)
|
||||
}
|
||||
|
||||
fn send<B: Bus>(
|
||||
fn _send<B: Bus>(
|
||||
&mut self,
|
||||
bus: &mut B,
|
||||
data: &[u8],
|
||||
) -> Result<usize, TcpSocketError<B::Error>> {
|
||||
if !self.is_connected(bus)? {
|
||||
if !self._is_connected(bus)? {
|
||||
return Err(TcpSocketError::NotReady);
|
||||
}
|
||||
|
||||
|
|
@ -166,12 +166,12 @@ impl TcpSocket {
|
|||
Ok(write_data.len())
|
||||
}
|
||||
|
||||
fn receive<B: Bus>(
|
||||
fn _receive<B: Bus>(
|
||||
&mut self,
|
||||
bus: &mut B,
|
||||
data: &mut [u8],
|
||||
) -> Result<usize, TcpSocketError<B::Error>> {
|
||||
if !self.is_connected(bus)? {
|
||||
if !self._is_connected(bus)? {
|
||||
return Err(TcpSocketError::NotReady);
|
||||
}
|
||||
|
||||
|
|
@ -222,19 +222,18 @@ impl<SpiBus: Bus, HostImpl: Host> TcpClientStack for DeviceRefMut<'_, SpiBus, Ho
|
|||
socket: &mut Self::TcpSocket,
|
||||
remote: SocketAddr,
|
||||
) -> nb::Result<(), Self::Error> {
|
||||
if let SocketAddr::V4(remote) = remote {
|
||||
// TODO dynamically select a random port
|
||||
socket.open(&mut self.bus, 49849 + u16::from(socket.socket.index))?; // chosen by fair dice roll.
|
||||
socket.connect(&mut self.bus, remote)?;
|
||||
let SocketAddr::V4(remote) = remote else {
|
||||
return Err(nb::Error::Other(Self::Error::UnsupportedAddress))
|
||||
};
|
||||
// TODO dynamically select a random port
|
||||
socket.open(&mut self.bus, 49849 + u16::from(socket.socket.index))?; // chosen by fair dice roll.
|
||||
socket._connect(&mut self.bus, remote)?;
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(nb::Error::Other(Self::Error::UnsupportedAddress))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_connected(&mut self, socket: &Self::TcpSocket) -> Result<bool, Self::Error> {
|
||||
socket.is_connected(&mut self.bus)
|
||||
socket._is_connected(&mut self.bus)
|
||||
}
|
||||
|
||||
fn send(
|
||||
|
|
@ -242,7 +241,7 @@ impl<SpiBus: Bus, HostImpl: Host> TcpClientStack for DeviceRefMut<'_, SpiBus, Ho
|
|||
socket: &mut Self::TcpSocket,
|
||||
buffer: &[u8],
|
||||
) -> nb::Result<usize, Self::Error> {
|
||||
let len = socket.send(&mut self.bus, buffer)?;
|
||||
let len = socket._send(&mut self.bus, buffer)?;
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
|
|
@ -251,11 +250,11 @@ impl<SpiBus: Bus, HostImpl: Host> TcpClientStack for DeviceRefMut<'_, SpiBus, Ho
|
|||
socket: &mut Self::TcpSocket,
|
||||
buffer: &mut [u8],
|
||||
) -> nb::Result<usize, Self::Error> {
|
||||
Ok(socket.receive(&mut self.bus, buffer)?)
|
||||
Ok(socket._receive(&mut self.bus, buffer)?)
|
||||
}
|
||||
|
||||
fn close(&mut self, socket: Self::TcpSocket) -> Result<(), Self::Error> {
|
||||
socket.close(&mut self.bus)?;
|
||||
socket._close(&mut self.bus)?;
|
||||
self.release_socket(socket.socket);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue