1use std::{io, net::Ipv4Addr};
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 source address")]
21 InvalidSourceAddress,
22
23 #[error("MCTX: invalid interface address")]
25 InvalidInterfaceAddress,
26
27 #[error("MCTX: publication already exists")]
29 DuplicatePublication,
30
31 #[error("MCTX: publication not found")]
33 PublicationNotFound,
34
35 #[error("MCTX: failed to create UDP socket: {0}")]
37 SocketCreateFailed(io::Error),
38
39 #[error("MCTX: failed to set socket option: {0}")]
41 SocketOptionFailed(io::Error),
42
43 #[error("MCTX: failed to bind UDP socket: {0}")]
45 SocketBindFailed(io::Error),
46
47 #[error("MCTX: failed to connect UDP socket: {0}")]
49 SocketConnectFailed(io::Error),
50
51 #[error("MCTX: failed to read local address from socket: {0}")]
53 SocketLocalAddrFailed(io::Error),
54
55 #[error("MCTX: existing socket must be an IPv4 UDP socket")]
57 ExistingSocketMustBeIpv4,
58
59 #[error("MCTX: existing socket is bound to UDP port {actual}, expected {expected}")]
61 ExistingSocketPortMismatch { expected: u16, actual: u16 },
62
63 #[error("MCTX: existing socket is bound to local IPv4 address {actual}, expected {expected}")]
65 ExistingSocketAddressMismatch {
66 expected: Ipv4Addr,
67 actual: Ipv4Addr,
68 },
69
70 #[error("MCTX: send failed: {0}")]
72 SendFailed(io::Error),
73}
74
75impl MctxError {
76 #[cfg(feature = "tokio")]
77 pub(crate) fn is_would_block(&self) -> bool {
78 matches!(self, Self::SendFailed(error) if error.kind() == io::ErrorKind::WouldBlock)
79 }
80}