pub trait Socket: AsRawFd {
type FrameType;
// Required methods
fn open_addr(addr: &CanAddr) -> Result<Self>
where Self: Sized;
fn read_frame(&self) -> Result<Self::FrameType>;
fn write_frame<F>(&self, frame: &F) -> Result<()>
where F: Into<Self::FrameType> + AsPtr;
// Provided methods
fn open(ifname: &str) -> Result<Self>
where Self: Sized { ... }
fn open_iface(ifindex: u32) -> Result<Self>
where Self: Sized { ... }
fn set_nonblocking(&self, nonblocking: bool) -> Result<()> { ... }
fn set_read_timeout(&self, duration: Duration) -> Result<()> { ... }
fn set_write_timeout(&self, duration: Duration) -> Result<()> { ... }
fn read_frame_timeout(&self, timeout: Duration) -> Result<Self::FrameType> { ... }
fn write_frame_insist<F>(&self, frame: &F) -> Result<()>
where F: Into<Self::FrameType> + AsPtr { ... }
}
Expand description
Common trait for SocketCAN sockets.
Note that a socket it created by opening it, and then closed by dropping it.
Required Associated Types§
Required Methods§
sourcefn read_frame(&self) -> Result<Self::FrameType>
fn read_frame(&self) -> Result<Self::FrameType>
Blocking read a single can frame.
sourcefn write_frame<F>(&self, frame: &F) -> Result<()>where
F: Into<Self::FrameType> + AsPtr,
fn write_frame<F>(&self, frame: &F) -> Result<()>where F: Into<Self::FrameType> + AsPtr,
Write a single can frame.
Note that this function can fail with an EAGAIN
error or similar.
Use write_frame_insist
if you need to be sure that the message got
sent or failed.
Writes a normal CAN 2.0 frame to the socket.
Provided Methods§
sourcefn open(ifname: &str) -> Result<Self>where
Self: Sized,
fn open(ifname: &str) -> Result<Self>where Self: Sized,
Open a named CAN device.
Usually the more common case, opens a socket can device by name, such as “can0”, “vcan0”, or “socan0”.
sourcefn open_iface(ifindex: u32) -> Result<Self>where
Self: Sized,
fn open_iface(ifindex: u32) -> Result<Self>where Self: Sized,
Open CAN device by interface number.
Opens a CAN device by kernel interface number.
sourcefn set_nonblocking(&self, nonblocking: bool) -> Result<()>
fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Change socket to non-blocking mode or back to blocking mode.
sourcefn set_read_timeout(&self, duration: Duration) -> Result<()>
fn set_read_timeout(&self, duration: Duration) -> Result<()>
Sets the read timeout on the socket
For convenience, the result value can be checked using
ShouldRetry::should_retry
when a timeout is set.
sourcefn set_write_timeout(&self, duration: Duration) -> Result<()>
fn set_write_timeout(&self, duration: Duration) -> Result<()>
Sets the write timeout on the socket
sourcefn read_frame_timeout(&self, timeout: Duration) -> Result<Self::FrameType>
fn read_frame_timeout(&self, timeout: Duration) -> Result<Self::FrameType>
Blocking read a single can frame with timeout.