pub trait Socket: AsRawFd {
type FrameType;
Show 15 methods
// Required methods
fn open_addr(addr: &CanAddr) -> IoResult<Self>
where Self: Sized;
fn as_raw_socket(&self) -> &Socket ⓘ;
fn as_raw_socket_mut(&mut self) -> &mut Socket ⓘ;
fn read_frame(&self) -> IoResult<Self::FrameType>;
fn write_frame<F>(&self, frame: &F) -> IoResult<()>
where F: Into<Self::FrameType> + AsPtr;
// Provided methods
fn open(ifname: &str) -> IoResult<Self>
where Self: Sized { ... }
fn open_iface(ifindex: u32) -> IoResult<Self>
where Self: Sized { ... }
fn nonblocking(&self) -> IoResult<bool> { ... }
fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()> { ... }
fn read_timeout(&self) -> IoResult<Option<Duration>> { ... }
fn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
where D: Into<Option<Duration>> { ... }
fn write_timeout(&self) -> IoResult<Option<Duration>> { ... }
fn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
where D: Into<Option<Duration>> { ... }
fn read_frame_timeout(&self, timeout: Duration) -> IoResult<Self::FrameType> { ... }
fn write_frame_insist<F>(&self, frame: &F) -> IoResult<()>
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 as_raw_socket(&self) -> &Socket ⓘ
fn as_raw_socket(&self) -> &Socket ⓘ
Gets a shared reference to the underlying socket object
Sourcefn as_raw_socket_mut(&mut self) -> &mut Socket ⓘ
fn as_raw_socket_mut(&mut self) -> &mut Socket ⓘ
Gets a mutable reference to the underlying socket object
Sourcefn read_frame(&self) -> IoResult<Self::FrameType>
fn read_frame(&self) -> IoResult<Self::FrameType>
Blocking read a single can frame.
Provided Methods§
Sourcefn open(ifname: &str) -> IoResult<Self>where
Self: Sized,
fn open(ifname: &str) -> IoResult<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) -> IoResult<Self>where
Self: Sized,
fn open_iface(ifindex: u32) -> IoResult<Self>where
Self: Sized,
Open CAN device by interface number.
Opens a CAN device by kernel interface number.
Sourcefn nonblocking(&self) -> IoResult<bool>
fn nonblocking(&self) -> IoResult<bool>
Determines if the socket is currently in nonblocking mode.
Sourcefn set_nonblocking(&self, nonblocking: bool) -> IoResult<()>
fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()>
Change socket to non-blocking mode or back to blocking mode.
Sourcefn read_timeout(&self) -> IoResult<Option<Duration>>
fn read_timeout(&self) -> IoResult<Option<Duration>>
Gets the read timeout on the socket, if any.
Sourcefn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
fn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
Sets the read timeout on the socket
For convenience, the result value can be checked using
ShouldRetry::should_retry
when a timeout is set.
If the duration is set to None
then write calls will block
indefinitely.
Sourcefn write_timeout(&self) -> IoResult<Option<Duration>>
fn write_timeout(&self) -> IoResult<Option<Duration>>
Gets the write timeout on the socket, if any.
Sourcefn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
fn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
Sets the write timeout on the socket
If the duration is set to None
then write calls will block
indefinitely.
Sourcefn read_frame_timeout(&self, timeout: Duration) -> IoResult<Self::FrameType>
fn read_frame_timeout(&self, timeout: Duration) -> IoResult<Self::FrameType>
Blocking read a single can frame with timeout.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.