Thanks to visit codestin.com
Credit goes to docs.rs

Socket

Trait Socket 

Source
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§

Source

type FrameType

The type of CAN frame that can be read and written by the socket.

This is typically distinguished by the size of the supported frame, with the primary difference between a CanFrame and a CanFdFrame.

Required Methods§

Source

fn open_addr(addr: &CanAddr) -> IoResult<Self>
where Self: Sized,

Open a CAN socket by address.

Source

fn as_raw_socket(&self) -> &Socket

Gets a shared reference to the underlying socket object

Source

fn as_raw_socket_mut(&mut self) -> &mut Socket

Gets a mutable reference to the underlying socket object

Source

fn read_frame(&self) -> IoResult<Self::FrameType>

Blocking read a single can frame.

Source

fn write_frame<F>(&self, frame: &F) -> IoResult<()>
where F: Into<Self::FrameType> + AsPtr,

Writes a normal CAN 2.0 frame to the socket.

Provided Methods§

Source

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”.

Source

fn open_iface(ifindex: u32) -> IoResult<Self>
where Self: Sized,

Open CAN device by interface number.

Opens a CAN device by kernel interface number.

Source

fn nonblocking(&self) -> IoResult<bool>

Determines if the socket is currently in nonblocking mode.

Source

fn set_nonblocking(&self, nonblocking: bool) -> IoResult<()>

Change socket to non-blocking mode or back to blocking mode.

Source

fn read_timeout(&self) -> IoResult<Option<Duration>>

Gets the read timeout on the socket, if any.

Source

fn set_read_timeout<D>(&self, duration: D) -> IoResult<()>
where D: Into<Option<Duration>>,

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.

Source

fn write_timeout(&self) -> IoResult<Option<Duration>>

Gets the write timeout on the socket, if any.

Source

fn set_write_timeout<D>(&self, duration: D) -> IoResult<()>
where D: Into<Option<Duration>>,

Sets the write timeout on the socket

If the duration is set to None then write calls will block indefinitely.

Source

fn read_frame_timeout(&self, timeout: Duration) -> IoResult<Self::FrameType>

Blocking read a single can frame with timeout.

Source

fn write_frame_insist<F>(&self, frame: &F) -> IoResult<()>
where F: Into<Self::FrameType> + AsPtr,

Blocking write a single can frame, retrying until it gets sent successfully.

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.

Implementors§