mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 10:53:58 +00:00
Make bigtcp error wrappers consistent
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
bfc71d1b27
commit
7334c93ff5
@ -23,7 +23,10 @@ use super::{
|
||||
RawTcpSocket, RawUdpSocket, TcpStateCheck,
|
||||
};
|
||||
use crate::{
|
||||
errors::tcp::{ConnectError, ListenError},
|
||||
errors::{
|
||||
tcp::{ConnectError, ListenError},
|
||||
udp::SendError,
|
||||
},
|
||||
ext::Ext,
|
||||
iface::{BindPortConfig, BoundPort, Iface},
|
||||
socket_table::{ConnectionKey, ListenerKey},
|
||||
@ -31,7 +34,7 @@ use crate::{
|
||||
|
||||
pub struct Socket<T: Inner<E>, E: Ext>(Takeable<Arc<SocketBg<T, E>>>);
|
||||
|
||||
/// [`TcpConnectionInner`] or [`UdpSocketInner`].
|
||||
/// [`TcpConnectionInner`], [`TcpListenerInner`], or [`UdpSocketInner`].
|
||||
pub trait Inner<E: Ext> {
|
||||
type Observer: SocketEventObserver;
|
||||
|
||||
@ -59,7 +62,7 @@ pub struct SocketBg<T: Inner<E>, E: Ext> {
|
||||
next_poll_at_ms: AtomicU64,
|
||||
}
|
||||
|
||||
/// States needed by [`TcpConnectionBg`] but not [`UdpSocketBg`].
|
||||
/// States needed by [`TcpConnectionBg`].
|
||||
pub struct TcpConnectionInner<E: Ext> {
|
||||
socket: SpinLock<RawTcpSocketExt<E>, LocalIrqDisabled>,
|
||||
is_dead: AtomicBool,
|
||||
@ -204,6 +207,7 @@ pub struct TcpBacklog<E: Ext> {
|
||||
connected: Vec<TcpConnection<E>>,
|
||||
}
|
||||
|
||||
/// States needed by [`TcpListenerBg`].
|
||||
pub struct TcpListenerInner<E: Ext> {
|
||||
backlog: SpinLock<TcpBacklog<E>, LocalIrqDisabled>,
|
||||
listener_key: ListenerKey,
|
||||
@ -242,7 +246,7 @@ impl<E: Ext> Inner<E> for TcpListenerInner<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// States needed by [`UdpSocketBg`] but not [`TcpConnectionBg`].
|
||||
/// States needed by [`UdpSocketBg`].
|
||||
type UdpSocketInner = SpinLock<Box<RawUdpSocket>, LocalIrqDisabled>;
|
||||
|
||||
impl<E: Ext> Inner<E> for UdpSocketInner {
|
||||
@ -631,14 +635,10 @@ impl<E: Ext> UdpSocket<E> {
|
||||
size: usize,
|
||||
meta: impl Into<UdpMetadata>,
|
||||
f: F,
|
||||
) -> Result<R, crate::errors::udp::SendError>
|
||||
) -> Result<R, SendError>
|
||||
where
|
||||
F: FnOnce(&mut [u8]) -> R,
|
||||
{
|
||||
use smoltcp::socket::udp::SendError as SendErrorInner;
|
||||
|
||||
use crate::errors::udp::SendError;
|
||||
|
||||
let mut socket = self.0.inner.lock();
|
||||
|
||||
if size > socket.packet_send_capacity() {
|
||||
@ -647,8 +647,7 @@ impl<E: Ext> UdpSocket<E> {
|
||||
|
||||
let buffer = match socket.send(size, meta) {
|
||||
Ok(data) => data,
|
||||
Err(SendErrorInner::Unaddressable) => return Err(SendError::Unaddressable),
|
||||
Err(SendErrorInner::BufferFull) => return Err(SendError::BufferFull),
|
||||
Err(err) => return Err(err.into()),
|
||||
};
|
||||
let result = f(buffer);
|
||||
self.0.update_next_poll_at_ms(PollAt::Now);
|
||||
|
Reference in New Issue
Block a user