tokio-socketcan

Crates.iotokio-socketcan
lib.rstokio-socketcan
version0.3.1
sourcesrc
created_at2019-01-10 04:00:21.442006
updated_at2021-11-17 16:04:58.600223
descriptionAsynchronous Linux SocketCAN sockets with tokio
homepage
repositoryhttps://github.com/oefd/tokio-socketcan
max_upload_size
id107707
size26,511
Marcel (marcelbuesing)

documentation

README

crates.io badge documentation Continuous integration

tokio-socketcan

SocketCAN support for tokio based on the socketcan crate.

Example echo server

use futures_util::stream::StreamExt;
use tokio_socketcan::{CANSocket, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let mut socket_rx = CANSocket::open("vcan0")?;
    let socket_tx = CANSocket::open("vcan0")?;
    while let Some(Ok(frame)) = socket_rx.next().await {
        socket_tx.write_frame(frame)?.await?;
    }
    Ok(())
}

Testing

Integrating the test into a CI system is non-trivial as it relies on a vcan0 virtual can device existing. Adding one to most linux systems is pretty easy with root access but attaching a vcan device to a container for CI seems difficult to find support for.

To run the tests locally, though, setup should be simple:

sudo modprobe vcan
sudo ip link add vcan0 type vcan
sudo ip link set vcan0 up
cargo test
Commit count: 29

cargo fmt