1use ax_io::IoError;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
5pub enum NetError {
6 #[error("network address is already in use")]
8 AddrInUse,
9 #[error("socket is already connected")]
11 AlreadyConnected,
12 #[error("network object already exists")]
14 AlreadyExists,
15 #[error("network object is in an invalid state")]
17 BadState,
18 #[error("bad network address")]
20 BadAddress,
21 #[error("bad network file descriptor")]
23 BadFileDescriptor,
24 #[error("network stream is broken")]
26 BrokenPipe,
27 #[error("connection was refused")]
29 ConnectionRefused,
30 #[error("connection was reset")]
32 ConnectionReset,
33 #[error("socket path operation crosses devices")]
35 CrossesDevices,
36 #[error("socket path directory is not empty")]
38 DirectoryNotEmpty,
39 #[error("destination address is required")]
41 DestAddrRequired,
42 #[error("socket path traversal loop detected")]
44 FilesystemLoop,
45 #[error("socket path object is too large")]
47 FileTooLarge,
48 #[error("connection is in progress")]
50 InProgress,
51 #[error("network operation was interrupted")]
53 Interrupted,
54 #[error("invalid network input")]
56 InvalidInput,
57 #[error("socket path data is invalid")]
59 InvalidData,
60 #[error("socket path is a directory")]
62 IsADirectory,
63 #[error("network message is too long")]
65 MessageTooLong,
66 #[error("socket path name is too long")]
68 NameTooLong,
69 #[error("network allocation failed")]
71 NoMemory,
72 #[error("network device does not exist")]
74 NoSuchDevice,
75 #[error("network device or address does not exist")]
77 NoSuchDeviceOrAddress,
78 #[error("socket is not connected")]
80 NotConnected,
81 #[error("network object was not found")]
83 NotFound,
84 #[error("socket path component is not a directory")]
86 NotADirectory,
87 #[error("object is not a socket")]
89 NotASocket,
90 #[error("socket object is not a tty")]
92 NotATty,
93 #[error("network operation is not permitted")]
95 OperationNotPermitted,
96 #[error("network operation is not supported")]
98 OperationNotSupported,
99 #[error("socket address family is not supported")]
101 AddressFamilyUnsupported,
102 #[error("socket protocol option is not supported")]
104 ProtocolOptionUnsupported,
105 #[error("socket path permission denied")]
107 PermissionDenied,
108 #[error("socket path filesystem is read-only")]
110 ReadOnlyFilesystem,
111 #[error("network resource is busy")]
113 ResourceBusy,
114 #[error("socket path storage is full")]
116 StorageFull,
117 #[error("network operation timed out")]
119 TimedOut,
120 #[error("network capability is unavailable")]
122 Unsupported,
123 #[error("trusted wireless connection entropy is unavailable")]
125 EntropyUnavailable,
126 #[error("network operation would block")]
128 WouldBlock,
129 #[error(transparent)]
131 Io(#[from] IoError),
132 #[error("network backend I/O failed")]
134 BackendIo,
135}
136
137pub type NetResult<T = ()> = Result<T, NetError>;
139
140impl From<NetError> for IoError {
141 fn from(error: NetError) -> Self {
142 match error {
143 NetError::AddrInUse => Self::AddrInUse,
144 NetError::AlreadyConnected => Self::AlreadyConnected,
145 NetError::AlreadyExists => Self::AlreadyExists,
146 NetError::BadState => Self::BadState,
147 NetError::BadAddress => Self::BadAddress,
148 NetError::BadFileDescriptor => Self::BadFileDescriptor,
149 NetError::BrokenPipe => Self::BrokenPipe,
150 NetError::ConnectionRefused => Self::ConnectionRefused,
151 NetError::ConnectionReset => Self::ConnectionReset,
152 NetError::CrossesDevices => Self::CrossesDevices,
153 NetError::DirectoryNotEmpty => Self::DirectoryNotEmpty,
154 NetError::DestAddrRequired => Self::DestAddrRequired,
155 NetError::FilesystemLoop => Self::FilesystemLoop,
156 NetError::FileTooLarge => Self::FileTooLarge,
157 NetError::InProgress => Self::InProgress,
158 NetError::Interrupted => Self::Interrupted,
159 NetError::InvalidInput => Self::InvalidInput,
160 NetError::InvalidData => Self::InvalidData,
161 NetError::IsADirectory => Self::IsADirectory,
162 NetError::MessageTooLong => Self::MessageTooLong,
163 NetError::NameTooLong => Self::NameTooLong,
164 NetError::NoMemory => Self::NoMemory,
165 NetError::NoSuchDevice => Self::NoSuchDevice,
166 NetError::NoSuchDeviceOrAddress => Self::NoSuchDeviceOrAddress,
167 NetError::NotConnected => Self::NotConnected,
168 NetError::NotFound => Self::NotFound,
169 NetError::NotADirectory => Self::NotADirectory,
170 NetError::NotASocket => Self::NotASocket,
171 NetError::NotATty => Self::NotATty,
172 NetError::OperationNotPermitted => Self::OperationNotPermitted,
173 NetError::OperationNotSupported => Self::OperationNotSupported,
174 NetError::AddressFamilyUnsupported => Self::AddressFamilyUnsupported,
175 NetError::ProtocolOptionUnsupported => Self::ProtocolOptionUnsupported,
176 NetError::PermissionDenied => Self::PermissionDenied,
177 NetError::ReadOnlyFilesystem => Self::ReadOnlyFilesystem,
178 NetError::ResourceBusy => Self::ResourceBusy,
179 NetError::StorageFull => Self::StorageFull,
180 NetError::TimedOut => Self::TimedOut,
181 NetError::Unsupported => Self::Unsupported,
182 NetError::EntropyUnavailable => Self::OperationNotSupported,
183 NetError::WouldBlock => Self::WouldBlock,
184 NetError::Io(error) => error,
185 NetError::BackendIo => Self::Io,
186 }
187 }
188}