Skip to main content

virtio_drivers/device/socket/
error.rs

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