use ax_io::IoError;
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
pub enum NetError {
#[error("network address is already in use")]
AddrInUse,
#[error("socket is already connected")]
AlreadyConnected,
#[error("network object already exists")]
AlreadyExists,
#[error("network object is in an invalid state")]
BadState,
#[error("bad network address")]
BadAddress,
#[error("bad network file descriptor")]
BadFileDescriptor,
#[error("network stream is broken")]
BrokenPipe,
#[error("connection was refused")]
ConnectionRefused,
#[error("connection was reset")]
ConnectionReset,
#[error("socket path operation crosses devices")]
CrossesDevices,
#[error("socket path directory is not empty")]
DirectoryNotEmpty,
#[error("destination address is required")]
DestAddrRequired,
#[error("socket path traversal loop detected")]
FilesystemLoop,
#[error("socket path object is too large")]
FileTooLarge,
#[error("connection is in progress")]
InProgress,
#[error("network operation was interrupted")]
Interrupted,
#[error("invalid network input")]
InvalidInput,
#[error("socket path data is invalid")]
InvalidData,
#[error("socket path is a directory")]
IsADirectory,
#[error("network message is too long")]
MessageTooLong,
#[error("socket path name is too long")]
NameTooLong,
#[error("network allocation failed")]
NoMemory,
#[error("network device does not exist")]
NoSuchDevice,
#[error("network device or address does not exist")]
NoSuchDeviceOrAddress,
#[error("socket is not connected")]
NotConnected,
#[error("network object was not found")]
NotFound,
#[error("socket path component is not a directory")]
NotADirectory,
#[error("object is not a socket")]
NotASocket,
#[error("socket object is not a tty")]
NotATty,
#[error("network operation is not permitted")]
OperationNotPermitted,
#[error("network operation is not supported")]
OperationNotSupported,
#[error("socket address family is not supported")]
AddressFamilyUnsupported,
#[error("socket protocol option is not supported")]
ProtocolOptionUnsupported,
#[error("socket path permission denied")]
PermissionDenied,
#[error("socket path filesystem is read-only")]
ReadOnlyFilesystem,
#[error("network resource is busy")]
ResourceBusy,
#[error("socket path storage is full")]
StorageFull,
#[error("network operation timed out")]
TimedOut,
#[error("network capability is unavailable")]
Unsupported,
#[error("trusted wireless connection entropy is unavailable")]
EntropyUnavailable,
#[error("network operation would block")]
WouldBlock,
#[error(transparent)]
Io(#[from] IoError),
#[error("network backend I/O failed")]
BackendIo,
}
pub type NetResult<T = ()> = Result<T, NetError>;
impl From<NetError> for IoError {
fn from(error: NetError) -> Self {
match error {
NetError::AddrInUse => Self::AddrInUse,
NetError::AlreadyConnected => Self::AlreadyConnected,
NetError::AlreadyExists => Self::AlreadyExists,
NetError::BadState => Self::BadState,
NetError::BadAddress => Self::BadAddress,
NetError::BadFileDescriptor => Self::BadFileDescriptor,
NetError::BrokenPipe => Self::BrokenPipe,
NetError::ConnectionRefused => Self::ConnectionRefused,
NetError::ConnectionReset => Self::ConnectionReset,
NetError::CrossesDevices => Self::CrossesDevices,
NetError::DirectoryNotEmpty => Self::DirectoryNotEmpty,
NetError::DestAddrRequired => Self::DestAddrRequired,
NetError::FilesystemLoop => Self::FilesystemLoop,
NetError::FileTooLarge => Self::FileTooLarge,
NetError::InProgress => Self::InProgress,
NetError::Interrupted => Self::Interrupted,
NetError::InvalidInput => Self::InvalidInput,
NetError::InvalidData => Self::InvalidData,
NetError::IsADirectory => Self::IsADirectory,
NetError::MessageTooLong => Self::MessageTooLong,
NetError::NameTooLong => Self::NameTooLong,
NetError::NoMemory => Self::NoMemory,
NetError::NoSuchDevice => Self::NoSuchDevice,
NetError::NoSuchDeviceOrAddress => Self::NoSuchDeviceOrAddress,
NetError::NotConnected => Self::NotConnected,
NetError::NotFound => Self::NotFound,
NetError::NotADirectory => Self::NotADirectory,
NetError::NotASocket => Self::NotASocket,
NetError::NotATty => Self::NotATty,
NetError::OperationNotPermitted => Self::OperationNotPermitted,
NetError::OperationNotSupported => Self::OperationNotSupported,
NetError::AddressFamilyUnsupported => Self::AddressFamilyUnsupported,
NetError::ProtocolOptionUnsupported => Self::ProtocolOptionUnsupported,
NetError::PermissionDenied => Self::PermissionDenied,
NetError::ReadOnlyFilesystem => Self::ReadOnlyFilesystem,
NetError::ResourceBusy => Self::ResourceBusy,
NetError::StorageFull => Self::StorageFull,
NetError::TimedOut => Self::TimedOut,
NetError::Unsupported => Self::Unsupported,
NetError::EntropyUnavailable => Self::OperationNotSupported,
NetError::WouldBlock => Self::WouldBlock,
NetError::Io(error) => error,
NetError::BackendIo => Self::Io,
}
}
}