• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! This module contain the error from the VirtIO socket driver.
2 
3 use core::result;
4 use thiserror::Error;
5 
6 /// The error type of VirtIO socket driver.
7 #[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
8 pub enum SocketError {
9     /// There is an existing connection.
10     #[error("There is an existing connection. Please close the current connection before attempting to connect again.")]
11     ConnectionExists,
12     /// The device is not connected to any peer.
13     #[error("The device is not connected to any peer. Please connect it to a peer first.")]
14     NotConnected,
15     /// Peer socket is shutdown.
16     #[error("The peer socket is shutdown.")]
17     PeerSocketShutdown,
18     /// The given buffer is shorter than expected.
19     #[error("The given buffer is shorter than expected")]
20     BufferTooShort,
21     /// The given buffer for output is shorter than expected.
22     #[error("The given output buffer is too short. '{0}' bytes is needed for the output buffer.")]
23     OutputBufferTooShort(usize),
24     /// The given buffer has exceeded the maximum buffer size.
25     #[error("The given buffer length '{0}' has exceeded the maximum allowed buffer length '{1}'")]
26     BufferTooLong(usize, usize),
27     /// Unknown operation.
28     #[error("The operation code '{0}' is unknown")]
29     UnknownOperation(u16),
30     /// Invalid operation,
31     #[error("Invalid operation")]
32     InvalidOperation,
33     /// Invalid number.
34     #[error("Invalid number")]
35     InvalidNumber,
36     /// Unexpected data in packet.
37     #[error("No data is expected in the packet")]
38     UnexpectedDataInPacket,
39     /// Peer has insufficient buffer space, try again later.
40     #[error("Peer has insufficient buffer space, try again later")]
41     InsufficientBufferSpaceInPeer,
42     /// Recycled a wrong buffer.
43     #[error("Recycled a wrong buffer")]
44     RecycledWrongBuffer,
45 }
46 
47 pub type Result<T> = result::Result<T, SocketError>;
48