pub enum Error {
Os(Error),
Truncated,
BufferTooSmall {
needed: usize,
},
Interrupted,
ConnectionClosed,
Overrun,
WouldBlock,
UnexpectedConnector,
}Expand description
Errors that can occur during proc connector operations.
§Example: matching on errors
use proc_connector::Error;
fn handle_error(e: Error) -> String {
match &e {
Error::Os(e) => format!("os error: {e}"),
Error::Truncated => "truncated message".into(),
Error::BufferTooSmall { needed } => {
format!("need {needed} bytes")
}
Error::Interrupted => "interrupted, retry".into(),
Error::ConnectionClosed => "connection closed".into(),
Error::Overrun => "events dropped".into(),
Error::WouldBlock => "would block".into(),
Error::UnexpectedConnector => "unexpected connector".into(),
}
}
assert_eq!(handle_error(Error::Truncated), "truncated message");
assert_eq!(
handle_error(Error::BufferTooSmall { needed: 4096 }),
"need 4096 bytes"
);§Example: using the From<std::io::Error> impl
use proc_connector::Error;
fn returns_error() -> Result<(), Error> {
// std::io::Error is automatically converted via From
let _file = std::fs::File::open("/nonexistent")?;
Ok(())
}
let err = returns_error().unwrap_err();
assert!(matches!(err, Error::Os(_)));Variants§
Os(Error)
System call failed (socket/bind/sendmsg/recvmsg).
Wraps std::io::Error for maximum compatibility.
Truncated
Received message is shorter than the minimum protocol header size.
BufferTooSmall
Provided receive buffer is too small.
Interrupted
Receive was interrupted by a signal; the operation should be retried.
ConnectionClosed
The netlink connection was closed (recv returned 0).
Overrun
Kernel reports message overrun; some events may have been dropped.
The caller should increase buffer size or consume events faster.
WouldBlock
Non-blocking recv found no data available (EAGAIN / EWOULDBLOCK).
Only returned when the socket is in non-blocking mode. Callers should wait for fd readiness (e.g. via poll/AsyncFd) and retry.
UnexpectedConnector
收到的消息不是proc connector事件(cn_msg idx != CN_IDX_PROC)。
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()