1use std::io;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
6pub enum MctxError {
7 #[error("MCTX: invalid destination port")]
9 InvalidDestinationPort,
10
11 #[error("MCTX: group must be a multicast IPv4 address")]
13 InvalidMulticastGroup,
14
15 #[error("MCTX: invalid source port")]
17 InvalidSourcePort,
18
19 #[error("MCTX: invalid interface address")]
21 InvalidInterfaceAddress,
22
23 #[error("MCTX: publication already exists")]
25 DuplicatePublication,
26
27 #[error("MCTX: publication not found")]
29 PublicationNotFound,
30
31 #[error("MCTX: failed to create UDP socket: {0}")]
33 SocketCreateFailed(io::Error),
34
35 #[error("MCTX: failed to set socket option: {0}")]
37 SocketOptionFailed(io::Error),
38
39 #[error("MCTX: failed to bind UDP socket: {0}")]
41 SocketBindFailed(io::Error),
42
43 #[error("MCTX: failed to connect UDP socket: {0}")]
45 SocketConnectFailed(io::Error),
46
47 #[error("MCTX: failed to read local address from socket: {0}")]
49 SocketLocalAddrFailed(io::Error),
50
51 #[error("MCTX: existing socket must be an IPv4 UDP socket")]
53 ExistingSocketMustBeIpv4,
54
55 #[error("MCTX: existing socket is bound to UDP port {actual}, expected {expected}")]
57 ExistingSocketPortMismatch { expected: u16, actual: u16 },
58
59 #[error("MCTX: send failed: {0}")]
61 SendFailed(io::Error),
62}
63
64impl MctxError {
65 #[cfg(feature = "tokio")]
66 pub(crate) fn is_would_block(&self) -> bool {
67 matches!(self, Self::SendFailed(error) if error.kind() == io::ErrorKind::WouldBlock)
68 }
69}