Receive RST packets as ECONNRESET errors

This commit is contained in:
Ruihan Li
2025-02-24 23:07:58 +08:00
committed by Tate, Hongliang Tian
parent aa29640ed7
commit d40d452e9d
6 changed files with 256 additions and 31 deletions

View File

@ -10,8 +10,6 @@ pub enum BindError {
}
pub mod tcp {
pub use smoltcp::socket::tcp::{RecvError, SendError};
/// An error returned by [`TcpListener::new_listen`].
///
/// [`TcpListener::new_listen`]: crate::socket::TcpListener::new_listen
@ -51,6 +49,44 @@ pub mod tcp {
}
}
}
/// An error returned by [`TcpConnection::send`].
///
/// [`TcpConnection::send`]: crate::socket::TcpConnection::send
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SendError {
InvalidState,
/// The connection is reset.
ConnReset,
}
impl From<smoltcp::socket::tcp::SendError> for SendError {
fn from(value: smoltcp::socket::tcp::SendError) -> Self {
match value {
smoltcp::socket::tcp::SendError::InvalidState => Self::InvalidState,
}
}
}
/// An error returned by [`TcpConnection::recv`].
///
/// [`TcpConnection::recv`]: crate::socket::TcpConnection::recv
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum RecvError {
InvalidState,
Finished,
/// The connection is reset.
ConnReset,
}
impl From<smoltcp::socket::tcp::RecvError> for RecvError {
fn from(value: smoltcp::socket::tcp::RecvError) -> Self {
match value {
smoltcp::socket::tcp::RecvError::InvalidState => Self::InvalidState,
smoltcp::socket::tcp::RecvError::Finished => Self::Finished,
}
}
}
}
pub mod udp {