1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use maidsafe_utilities::serialisation::SerialisationError;
use safe_crypto;
use std::io;

// #[cfg(feature = "enable-udt")]
// use udt_extern::UdtError;
// #[cfg(not(feature = "enable-udt"))]
#[derive(Debug)]
/// NoOp without feature
pub struct UdtError {
    /// NoOp without feature
    pub err_msg: String,
}

quick_error! {
    /// Common module specific error
    #[derive(Debug)]
    pub enum SocketError {
        /// IO error
        Io(e: io::Error) {
            description(e.description())
            display("Io error: {}", e)
            cause(e)
            from()
        }
        /// Socket is uninitialised and invalid for any operation
        UninitialisedSocket {
            description("Socket is uninitialised and invalid for any operation")
            display("Socket is uninitialised and invalid for any operation")
        }
        /// Size of a message to send or about to be read is too large
        PayloadSizeProhibitive {
            description("Payload is too large")
        }
        /// Serialisation error
        Serialisation(e: SerialisationError) {
            description(e.description())
            display("Serialisation error: {}", e)
            cause(e)
            from()
        }
        /// A zero byte socket read - means EOF
        ZeroByteRead {
            description("Read zero bytes from the socket - indicates EOF")
        }
        /// UDT error
        Udt(e: UdtError) {
            description(&e.err_msg)
            display("Udt error: {}", e.err_msg)
            from()
        }
        /// UDP Socket is not connected
        UnconnectedUdpSocket {
            description("UDP Socket is not connected")
        }
        /// No UDT Epoll Loop
        NoUdtEpoll {
            description("No UDT Epoll while registering/deregistering")
        }
        /// UDT read has resulted in negative return value
        UdtNegativeBytesRead(val: i32) {
            description("UDT Read has resulted in a negative result. This is an error value.")
            display("UDT Read has resulted in a negative result. This is an error value: {}", val)
        }
        /// UDT write has resulted in negative return value
        UdtNegativeBytesWrite(val: i32) {
            description("UDT Write has resulted in a negative result. This is an error value.")
            display("UDT Write has resulted in a negative result. This is an error value: {}", val)
        }
        /// Crypto related error.
        Crypto(e: safe_crypto::Error) {
            display("Crypto related error: {}", e)
            from()
        }
    }
}